推 anyoilk:感謝您,我試出來了 03/13 13:51
※ 引述《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;
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.24.202
※ 編輯: wlsherica 來自: 140.112.24.202 (03/13 01:16)