For a dataset like the following one:
data example;
input interval zzz;
cards;
99 .345
100 -.398
101 .546
102 .968
103 -.012
104 .489
105 .005;
run;
how can I create 1 lead in variable zzz? I have found people recommending about PROC EXPAND, but I could not work that out. Would you please help?
Thank you.
Regards.
People recommending proc expand were right, as long as you have SAS/ETS licenced
proc expand data=example out=want;
id interval;
convert zzz=zzz_lead / transformout=(lead 1);
run;
So what should the results look like? Does the final observation get deleted?
Not sure if there is a BEST way. Here is an easy way. I assume you meant to include that last line of data in your example?
data example;
input interval zzz;
cards;
99 .345
100 -.398
101 .546
102 .968
103 -.012
104 .489
105 .005
;
data want ;
set example;
set example(firstobs=2 keep=zzz rename=(zzz=zzz_lead1)) example(obs=1 drop=_all_);
run;
zzz_ Obs interval zzz lead1 1 99 0.345 -0.398 2 100 -0.398 0.546 3 101 0.546 0.968 4 102 0.968 -0.012 5 103 -0.012 0.489 6 104 0.489 0.005 7 105 0.005 .
People recommending proc expand were right, as long as you have SAS/ETS licenced
proc expand data=example out=want;
id interval;
convert zzz=zzz_lead / transformout=(lead 1);
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.