我需要在三列中检查我的数据集中的相等值,然后添加两行都满足该条件。输出应该看起来像之前的行,但是有一个单元格具有总计值。
示例:
Security date flag volume CUSIP
A 20150707 1 100 xxx
B 20150708 0 100 xyz
B 20150708 0 200 xyz
B 20150709 1 150 xyz
C 20150709 0 100 yyy
C 20150710 1 200 yyy
C 20150710 1 300 yyy
D 20150710 2 100 zzz
输出:
A 20150707 1 100 xxx
B 20150708 0 300 xyz
B 20150709 1 150 xyz
C 20150709 0 100 yyy
C 20150710 1 500 yyy
D 20150710 2 100 zzz
我发现比较两行然后将它们总结为一个新变量有困难。
答案 0 :(得分:1)
希望这可以实现您的目标。
data have ;
input ColA $ ColB $ ColC ColD ColE $;
cards;
A 20150707 1 100 xxx
B 20150708 0 100 xyz
B 20150708 0 200 xyz
B 20150709 1 150 xyz
C 20150709 0 100 yyy
C 20150710 1 200 yyy
C 20150710 1 300 yyy
D 20150710 2 100 zzz
;
proc sql;
create table want as
select distinct ColA, ColB, colC, sum(ColD) as sumColD, colE
from have
group by ColA, colB
order by ColA, colB;
quit;