作者tew (咖啡王子)
站內Statistics
標題Re: [程式] SAS 直轉橫 proc transpose
時間Sat Sep 4 11:02:16 2010
我看了一下
你們的作法是考慮只有重複出現2次的情況
但是針對出現很多次 可能會有點麻煩
所以我簡單寫一下巨集
因為在外面用電腦 直接在BBS上寫 可能會有點錯誤 請見諒
data a;format in_date $20. out_date $20. start $20.;
input id no $ in_date $ out_date $ start $;
cards;
10011576 0032 2009/9/26 2009/10/8 .
10019076 0053 2009/7/7 2009/7/18 .
10034358 0004 2009/9/22 2009/9/22 2009/10/20
10034358 0005 2009/9/22 2009/11/10 2009/10/21
;
run;
proc sort data=a;by id in_date;
run;
data a;
set a;by id;
retain a 0;
a=a+1;
if first.id then a=1;
/*此處修正*/
run;
proc means noprint data=a;
var a;
output out=b(drop=_type_ _freq_) max=a;
run;
data _null_;
set b;
call symput('n',a);
run;
%macro a;
%do i=1 %to &n;
data a&i;
set a;
no&i=no;
in_date&i=in_date;
out_date&i=out_date;
start&i=start;
if a=&i then output;
keep id no&i in_date&i out_date&i start&i;
run;
%end;
data final;
merge
%do i=1 %to &n;
a&i
%end;
;by id;
run;
%mend;
%a;
以上語法 應該可以處理id出現2次以上的情況
你可以參考看看
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.129.9.83
※ 編輯: tew 來自: 220.129.9.83 (09/04 11:08)
推 socery:刪除if first.id then id=1; 09/04 12:01
※ 編輯: tew 來自: 220.129.9.225 (09/04 13:39)
→ socery:樸 我還真沒考慮到兩次以上的狀況=.= 09/04 18:08
推 wlsherica:(筆記) 感謝您 09/04 18:41