以下是一個方法...但想知道怎麼結合lag 和 macro做到
data temp1;
input test$ i;
cards;
A 1
B 2
C 2
D 1
E 3
F 1
G 5
;
run;
data temp2;
set temp1;
k=_n_-i;
j=_n_;
run;
proc sql;
create table temp3 as
select a.*,b.test as test2
from temp2 as a left join temp2 as b
on a.k=b.j
order by j;
quit;