id a b c
001 1 2 3
001 2 3 4
002 2 5 1
002 3 2 1
怎么样把 相同id的1行和2行加总,3 行和4 行加总?
得到 id a b c
001 3 5 7
002 5 7 2
谢谢指教

|
楼主: cxsyb
|
1782
5
[原创博文] 新手请教sas中对数据集的问题 |
|
大专生 30%
-
|
回帖推荐xiaosanmao 发表于3楼 查看完整内容 data x;
input id $ a b c@;
cards;
001 1 2 3
001 2 3 4
002 2 5 1
002 3 2 1
;run;
proc sql noprint;
create table final as
select id,sum(a) as a,sum(b) as b,
sum(c) as c from x group by id;quit;
楼上的程序比较简洁,我来段复杂的吧,也是数据量比较大的时候能用的上。
data raw;
input id $3. a b c;
cards;
001 1 2 3
001 2 3 4
002 2 5 1
002 3 2 1
;
proc sort data=raw;
by id;
data result(drop=a b c i);
set raw;
by id;
retain a1 b1 c1 0;
array aa(3) a b c;
array bb(3) a1 b1 c1;
do i=1 to 3;
bb(i)+aa(i);
if first.id then bb(i)=aa(i);
end;
if last.id;
ru ...
本帖被以下文库推荐
| ||
|
|
|
| ||
| ||
|
西格玛临床统计服务工作室http://www.sigma-stat.com/,luijb@163.com
|
||
加好友,备注cda京ICP备16021002号-2 京B2-20170662号
京公网安备 11010802022788号
论坛法律顾问:王进律师
知识产权保护声明
免责及隐私声明


