如果追求新data必须variable名字都一样。
data a;
input id group nlist;
cards;
1 0 23
1 1 31
2 0 5
3 0 41
3 1 22
3 2 19
3 3 9
;
data b(rename=(nlist=temp));
set a;
run;
data c;
set b;
by id;
if first.id then tot=temp;
else tot+temp;
rename tot=nlist;
drop temp;
run;
不然只需要核心就够了。
data a;
input id group nlist;
cards;
1 0 23
1 1 31
2 0 5
3 0 41
3 1 22
3 2 19
3 3 9
;
data c;
set a;
by id;
if first.id then tot=nlist;
else tot+nlist;
drop nlist;
run;