Re: [程式] SAS proc means 垂直加總
: 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://www.ptt.cc/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
討論串 (同標題文章)