看板 Statistics 關於我們 聯絡資訊
這問題如果是這樣 挺好玩的 底下的語法 是我個人的解法 你可以參考看看 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; proc sql; create table a as select a.comp_id, b.date from test a, test b where a.date>=b.date and (a.comp_id=1101 or a.comp_id=1102) order by comp_id,date; quit; ※ 引述《tew (咖啡王子)》之銘言: : : 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
imaltar:感謝~~我對SQL的用法還不是很善用阿XD~~ 06/24 15:23
richubby:哈 我們很多都還沒學過耶@@" 謝謝熱心的t高手!!!^^ 06/24 21:00