SAS 创建动态间隔 [英] SAS creating a dynamic interval

查看:27
本文介绍了SAS 创建动态间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这有点复杂(至少对我来说很好).

This is somewhat complex (well to me at least).

这是我必须做的:假设我有以下数据集:

Here is what I have to do: Say that I have the following dataset:

date    price   volume
02-Sep  40  100
03-Sep  45  200
04-Sep  46  150
05-Sep  43  300

假设我有一个断点,我希望在我的数据集中创建一个区间.例如,让我的断点 = 200 卷交易.

Say that I have a breakpoint where I wish to create an interval in my dataset. For instance, let my breakpoint = 200 volume transaction.

我想要的是创建一个 ID 列并为每个断点 = 200 记录一个 ID 变量 =1,2,3,....当您对每个 ID 的所有体积求和时,该值必须在所有 ID 中保持不变变量.

What I want is to create an ID column and record an ID variable =1,2,3,... for every breakpoint = 200. When you sum all the volume per ID, the value must be constant across all ID variables.

因此,使用上面的示例,我的最终数据集应如下所示:

So using my example above, my final dataset should look like the following:

date    price   volume  id
02-Sep  40  100 1
03-Sep  45  100 1
03-Sep  45  100 2
04-Sep  46  100 2
04-Sep  46  50  3
05-Sep  43  150 3
05-Sep  43  150 4 

(最后一行可能会丢失一些值,但这很好.我会踢掉最后一个 id)

(last row can miss some value but that is fine. I will kick out the last id)

如您所见,我必须分解"一些行(例如第二行,我将 200 分成两个 100 卷),以便使所有 ID 的卷的总和值 200 保持不变.

As you can see, I had to "decompose" some rows (like the second row for instance, I break the 200 into two 100 volume) in order to have constant value of the sum, 200, of volume across all ID.

推荐答案

看起来您正在为流量毒性 VPIN 计算进行体积分桶.我认为这可行:

Looks like you're doing volume bucketing for a flow toxicity VPIN calculation. I think this works:

%let bucketsize = 200;

data buckets(drop=bucket volume rename=(vol=volume));
    set tmp;
    retain bucket &bucketsize id 1;

    do until(volume=0);
        vol=min(volume,bucket);
        output;
        volume=volume-vol;
        bucket=bucket-vol;
        if bucket=0 then do;
            bucket=&bucketsize;
            id=id+1;
        end;
    end;
run;

我用您的数据集对此进行了测试,它看起来正确,但我会仔细检查几个案例以确认它是否正常工作.

I tested this with your dataset and it looks right, but I would check carefully several cases to confirm that it works right.

这篇关于SAS 创建动态间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆