看板 Statistics 關於我們 聯絡資訊
之前常常會遇到這個問題, 也有很多熱心的前輩幫助過我 剛好寫了一下這個小巨集, 希望對大家有一點幫助. /* front(data=你的資料,varold=想要front的變數,varnew=front完的變數,front=期數) */ %macro front(Data,varold,varnew,front); data &data; set &data; tempcount=_n_; output; run; proc sort data=&data; by decending tempcount; run; data &data; set &data; &varnew=lag&front(&varold); run; proc sort data=&data; by tempcount; run; data &data; set &data; drop tempcount; run; %mend; /*小小的測試*/ data temp; input test; cards; 1 2 4 4 5 6 7 ; run; %front(Data=temp,varold=test,varnew=testfront,front=3); proc print data=temp; run; /*輸出*/ test testfront 1 4 2 5 4 6 4 7 5 . 6 . 7 . -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 60.250.86.244
granzi:有沒有範 例輸 出的的結果 ? 05/17 04:20
※ 編輯: lsshno1 來自: 60.250.86.244 (05/17 12:53)
wlsherica:謝謝分享哩:) 05/17 13:11
tew:使用這個語法要小心 05/17 21:51
lsshno1:可以跟我說明一下嗎? 謝謝 05/17 23:47
tew:如果你的資料是 1980 1981 1982 1984 1985的格式 05/18 08:23
tew:中間缺了一年 就整個有問題 不是所有原始資料都很完美 05/18 08:24
tew:寫到巨集以後 可以開始思考不完美的情況 對你會有幫助的 05/18 08:27
lovesunshine:有用有推!!!!! 謝謝!!!!!! 03/11 23:26