也许一个愚蠢的问题......
我得到了以下数据集:
id count
x 1
y 2
z 3
a 1
b 2
c 3
etc.
我想要这个:
id count group
x 1 1
y 2 1
z 3 1
a 1 2
b 2 2
c 3 2
etc.
这是我的尝试:
data macro_1; set vix.macro_spy; where macro=1;
count+1;
if count>3 then do;
count=1;
end;
group=0;
if count=1 then group+1;
run;
但它不起作用。如果我一次得到“count = 1”,如何将所有“组”加一?
谢谢。
最佳答案
更简单
data want;
set vix.macro_spy;
group+(count=1);
run;
关于sas - 在 SAS 中计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14192112/