作者andersonhaha (好山好水 多健康)
看板Statistics
标题Re: [程式] SAS proc means 垂直加总
时间Sun May 10 23:29:00 2015
: id condition y1997 y1998 y1999 y2010
: 1 A 0 0 0 1
: 1 B 0 1 1 1
: 1 C 0 0 2 2
: 加总 0 1 3 4
: 2 A 2
: 2 B .. .. .. .. ..4
以 first.id 持续加总解决 以 2010 为例 have.sas
id condition y2010 sum
1 A 1
4
1 B 1
4
1 C 2
4
2 A 2
6
2 B 4
6
data want;
set have;
by id;
retain sum 0 sum_;
if first.id then sum=y2010;
else sum+y2010;
if last.id then output;
run;
proc sort data=want(keep=id sum);
by id; run;
data want_;
merge have want;
by id; run; 再 nodupkey 取得每个 id 当年的 vertical sum
------------------------------------
或以 Proc tabulate 解决
proc tabulate data=have;
class id;
class condition;
var y1997 y1998 y1999 y2000 ;
table id*(condition All='Sum'),
(y1997 y1998 y1999 y2000) * (sum=''*f=best5.)
;
run;
--
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 122.118.65.145
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Statistics/M.1431271743.A.B2B.html
※ 编辑: andersonhaha (122.118.65.145), 05/10/2015 23:29:56
※ 编辑: andersonhaha (220.132.200.210), 05/12/2015 00:37:03