看板 Statistics 關於我們 聯絡資訊
※ 引述《tea5 (茶)》之銘言: : ------------------------------------------------------------------------ : TITLE請著名軟體類別 : 按ctrl+v可預覽 發文前請把灰色的註解刪除 : 可使用ctrl+y刪除一整行 : [軟體程式類別]: : SAS : [程式問題]: : 資料處理 : [軟體熟悉度]: : 新手(不到1個月) : [問題敘述]: : 目前有三個變數 : ID YEAR COST : 1 2005 100 : 1 2006 100 : 1 2006 200 : 2 2004 100 : 2 2005 100 : 2 2005 100 : 2 2006 300 : 想得到 : ID YEAR COST TOTAL : 1 2005 100 100 : 1 2006 200 300 : 2 2004 100 100 : 2 2005 100 200 : 2 2006 300 300 : 的結果 : [程式範例]: : data new; : set old; : if first.cost then total=0; : total=cost+total; : run; : 使用first.這個function 好像有點問題 : 麻煩請高手修正,謝謝。 data a; input ID YEAR COST; cards; 1 2005 100 1 2006 100 1 2006 200 2 2004 100 2 2005 100 2 2005 100 2 2006 300 ; run; proc sort data=a;by id year; data b;set a; by id year; retain total; if first.year then do;total=0;end; total=cost+total; if last.year; run; -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.241.43.240 ※ 文章網址: http://www.ptt.cc/bbs/Statistics/M.1397980642.A.F99.html
tea5:感謝相助! 04/20 20:01