作者lsshno1 (朝右边锋迈进)
看板Statistics
标题[程式] sas, lag相反指令
时间Sun May 16 00:25:56 2010
之前常常会遇到这个问题, 也有很多热心的前辈帮助过我
刚好写了一下这个小巨集, 希望对大家有一点帮助.
/*
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
1F:推 granzi:有没有范 例输 出的的结果 ? 05/17 04:20
※ 编辑: lsshno1 来自: 60.250.86.244 (05/17 12:53)
2F:推 wlsherica:谢谢分享哩:) 05/17 13:11
3F:推 tew:使用这个语法要小心 05/17 21:51
4F:→ lsshno1:可以跟我说明一下吗? 谢谢 05/17 23:47
5F:推 tew:如果你的资料是 1980 1981 1982 1984 1985的格式 05/18 08:23
6F:→ tew:中间缺了一年 就整个有问题 不是所有原始资料都很完美 05/18 08:24
7F:推 tew:写到巨集以後 可以开始思考不完美的情况 对你会有帮助的 05/18 08:27
8F:推 lovesunshine:有用有推!!!!! 谢谢!!!!!! 03/11 23:26