看板 Statistics 關於我們 聯絡資訊
※ 引述《wlsherica (Mon_tresor)》之銘言: : ※ 引述《anyoilk (黑鼻頭)》之銘言: : : 現在我想把資料中的OWN變項(類別)內容筆數相加,變為下面: : : ID own NO : : 甲 1 1 : : 甲 1 2 : : 甲 2 1 : : 乙 1 1 : : 乙 2 1 : : 丙 1 1 : : 丙 1 2 : : 丙 2 1 : : 丙 2 2 : : 而我是試過下面的語法 : : data B; : : set A; : : by id; : : if first.id then NO=0; : : NO+own; : : run; : : 但跑出來,卻變成 : : ID own NO : : 甲 1 1 : : 甲 1 2 : : 甲 2 4 : : 乙 1 1 : : 乙 2 2 : : 丙 1 1 : : 丙 1 2 : : 丙 2 4 : : 丙 2 6 : : 我想破頭了,但還是卡住,請各位救救我,謝謝。 : 因為您提供的程式會一直累加, 試試看下面的語法: : proc sort data=a; /*原始檔名稱a*/ : by ID own; : data b; : set a; : by ID own; : if first.own=1 then no=0; : no+1; : output; : if last.own; : run; : proc print;run; 假設資料順序一開始就是對的 則在讀進資料以後 以下的語法就可以滿足你想要的 data a; set a; retain no 0; no=no+1; if id^=lag(id) then no=1; if own^=lag(own) then no=1; run; -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.44.204.168
anyoilk:感謝t大,這個方法也成功了 03/13 13:58