Re: [程式] SAS計數問題

看板Statistics作者 (..)時間4年前 (2022/01/24 10:35), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《steven225 (留戀)》之銘言: : 想請問,資料如下: : X : A : A : B : B : B : C : C : C : C : 若想要多一欄為前一欄變項的累加count,一欄為總count,如下: : X Y Z : A 1 2 : A 2 2 : B 1 3 : B 2 3 : B 3 3 : C 1 4 : C 2 4 : C 3 4 : C 4 4 : 該如何用proc freq來寫codes?還是需要用其它的指令?感謝 data AA; length X $5; input X; cards; A A B B B C C C C ; run; proc sort data=AA;by X;run; data AA;set AA;by X; retain Y; if first.X then do; Y=0;end; Y=Y+1; run; proc sql; create table AA as select a.*, b.Z from AA a left join (select X, count(*) as Z from AA group by X) b on a.X=b.X order by a.X, a.Y; quit; 參考看看~~ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.219.175.208 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Statistics/M.1642991727.A.B11.html
文章代碼(AID): #1XxX1liH (Statistics)
討論串 (同標題文章)
文章代碼(AID): #1XxX1liH (Statistics)