Re: [程式] sas資料選取問題

看板Statistics作者 (咖啡王子)時間15年前 (2010/06/24 14:46), 編輯推噓2(208)
留言10則, 2人參與, 最新討論串4/9 (看更多)
: : .. : : . : : 謝謝大家:D : data test;input comp_id date yymmdd8. a; : format date yymmddn8.; : cards; : 4212 20090415 0.15 1101 20090415 0.14 : 3232 20090416 1.23 1101 20090416 1.12 : 1101 20090417 2.33 1101 20090418 1.66 : 9232 20090418 1.66 : 8422 20090512 2.36 1101 20090512 2.33 : 1102 20090612 1.42 : 6473 20090613 2.42 : ; : run; 如果資料形式是這樣 下面的巨集如何抓出 1101 20090417以前的資料 我找不出您考量這部分的語法之處 當然 最主要是 我弄不懂原問者的問題 你可以再試試看 : %macro date(comp_id=,n=); : data _null_;set test(where=(comp_id in (&comp_id.))); : call symput('date',date);run; : data test&n.;set test(keep=date);comp_id=&comp_id.;if date <= &date.;run; : %mend; : %date(comp_id=1101,n=1); : %date(comp_id=1102,n=2); : data test;set test1 test2; : proc sort data=test;by comp_id date;run; : comp_id就是公司名,n=1表示產生test1這個資料,內容是comp_id=1101時日期小於 : 20090417的結果 : 最後的test合併test1 test2就是你想要的資料 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 134.208.29.183

06/24 14:49, , 1F
因為是他的資料公司是不重複的 有重複的話就要修改
06/24 14:49, 1F

06/24 14:54, , 2F
這樣他的資料 似乎也抓不出1101 20090417以外的資料
06/24 14:54, 2F

06/24 14:58, , 3F
可以阿 我是先抓1101所對應的資料 然後用call symput
06/24 14:58, 3F

06/24 15:00, , 4F
設定其對應的日期 也設定&comp_id為1101 然後用原本的資料
06/24 15:00, 4F

06/24 15:00, , 5F
每一個日期去跟設定的日期去比 取小於等於的 並且DROP掉
06/24 15:00, 5F

06/24 15:01, , 6F
原資料的comp_id 新產生的test1 設定comp_id為&comp_id
06/24 15:01, 6F

06/24 15:03, , 7F
因此可以抓到所有日期小於20090417的資料 只是comp_id都
06/24 15:03, 7F

06/24 15:03, , 8F
設成1101
06/24 15:03, 8F

06/24 15:04, , 9F
因為他後來希望的結果是希望公司名稱都是1101
06/24 15:04, 9F

06/24 15:11, , 10F
那我懂他的問題了
06/24 15:11, 10F
文章代碼(AID): #1C8lzF0s (Statistics)
討論串 (同標題文章)
文章代碼(AID): #1C8lzF0s (Statistics)