我一直在寻找解决方案,但是在社区的SAS中找不到任何类似的问题。
我在SAS中有下表。我需要按Date获取累计值。最重要的是,一旦累积值超过10,我就需要从new开始。
Date Number
01/01/2017 3
01/01/2017 1
01/01/2017 3
01/01/2017 4
01/01/2017 6
01/01/2017 8
02/01/2017 6
02/01/2017 3
02/01/2017 5
02/01/2017 7
03/01/2017 4
03/01/2017 3
... ...
我需要我的输出表如下所示。仅再一列显示累积值。
Date Number cumulative
01/01/2017 3 3
01/01/2017 1 4
01/01/2017 3 7
01/01/2017 4 4 <---- (starts from new)
01/01/2017 6 10
01/01/2017 8 8
02/01/2017 6 6
02/01/2017 3 9
02/01/2017 5 5
02/01/2017 7 7 <---- (starts from new)
03/01/2017 4 3
03/01/2017 3 7
... ... ...
有人可以协助这个问题吗?
谢谢
像(未经测试的)之类的东西:
data out;
set in;
by date; * Assumes sorted by date;
retain cumulative;
if first.date or cumulative+number > 10 then do;
cumulative = 0;
end;
cumulative = cumulative + number;
run;
应该管用...
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句