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

看板Statistics作者 (..)時間15年前 (2010/06/24 12:14), 編輯推噓1(101)
留言2則, 1人參與, 最新討論串2/9 (看更多)
※ 引述《richubby》之銘言: : SAS : [程式問題]: : 資料處理 : [軟體熟悉度]: : 低(1~3個月) : [問題敘述]: : 最近在跑資料的時候遇到一些問題想請問板上高手 : 公司代碼 日期 A變數 : 4212 20090415 0.15 : 3232 20090416 1.23 : 1101 20090417 2.33 : 9232 20090418 1.66 : 8422 20090512 2.36 : 1102 20090612 1.42 : 6473 20090613 2.42 : ... : .. : . : 想要抓1101公司20090417前的日期 : 與1102公司20090612前的日期 : 不知道問題有沒有講得很清楚..還是先謝謝大家了! : 希望的結果↓ : 1101 20090415 : 1101 20090416 : 1101 20090417 : 1102 20090415 : 1102 20090416 : 1102 20090417 : 1102 20090418 : 1102 20090512 : 1102 20090612 : ... : .. : . : 謝謝大家:D data test;input comp_id date yymmdd8. a; format date yymmddn8.; cards; 4212 20090415 0.15 3232 20090416 1.23 1101 20090417 2.33 9232 20090418 1.66 8422 20090512 2.36 1102 20090612 1.42 6473 20090613 2.42 ; run; %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: 114.43.125.210

06/24 12:27, , 1F
yeah 已經收到了 很謝謝您:)
06/24 12:27, 1F

06/24 12:28, , 2F
我們可能需要花一點時間去解讀一下巨集 哈哈"
06/24 12:28, 2F
文章代碼(AID): #1C8jkqnM (Statistics)
討論串 (同標題文章)
文章代碼(AID): #1C8jkqnM (Statistics)