Dear all,
I am trying to calculate next year value based on a panel data like below:
ID Year Value
1 1993 0.29
1 1994 0.65
1 1995 0.79
2 1993 1.23
2 1994 1.56
3 2001 0.98
3 2002 0.73
What I would want is to calculate lead(value). For example:
ID Year Value Value_nxt
1 1993 0.29 0.65
1 1994 0.65 0.79
1 1995 0.79
...................
Below is my code. Somehow it's not working right. Can anyone please tell me where went wrong and how I can fix this? Much appreciated!
proc sort data=have; by ID year; run;
data want; set have; by ID year;
if eof1=0 then set have (firstobs=2 rename=(value=value_nxt) ) end=eof1;
if last.ID then value_nxt=.;
run;
JOL
A small change might be enough:
if eof1=0 then set have (firstobs=2 keep=value rename=(value=value_nxt) ) end=eof1;
A small change might be enough:
if eof1=0 then set have (firstobs=2 keep=value rename=(value=value_nxt) ) end=eof1;
Yes It worked!!! Thanks a lot!
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.