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 lead1 lead2
1 1993 0.29 0.65 0.79
1 1994 0.65 0.79 1.23
1 1995 0.79 1.23
Please help me in creating lead1 and lead2.
Thanks!
How is it that in your output, in ROW 2, LEAD2 has a value of 1.23. Could you explain this?
How is it that in your output, in ROW 3, LEAD1 has a value of 1.23. Could you explain this?
Why in ROW 2 is LEAD2 = 1.23? Explain how you get that number. Don't just say, that's what you want, explain where the number comes from. Does ID play any role in this?
Assuming you did not intend for the last observations of ID=1 to get LEAD1 value from the first observation of ID2 (or the other example of propagating "lead" values accross ID's), then this should solve the problem. It is ready-made for use of a _TEMPORARY_ array to be built in the first pass of each id, and to retrieve in the second pass:
data want;
set have (in=firstpass) have (in=secondpass);
by id;
array values {1990:2001} _temporary_;
if first.id then call missing(of values{*});
if firstpass then values{year}=value;
if secondpass;
lead1=values{year+1};
lead2=values{year+2};
run;
Just make sure to specify upper and lower bounds for array VALUES to cover your entire data range.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.