BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JOLSAS
Quartz | Level 8

Dear all,

 

I am trying to calculate next year value based on a panel data like below:

 

ID                Year                Value

                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

                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

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

A small change might be enough:

 

 if eof1=0 then set have (firstobs=2 keep=value rename=(value=value_nxt) ) end=eof1;

View solution in original post

2 REPLIES 2
Astounding
PROC Star

A small change might be enough:

 

 if eof1=0 then set have (firstobs=2 keep=value rename=(value=value_nxt) ) end=eof1;

JOLSAS
Quartz | Level 8

Yes It worked!!! Thanks a lot!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to connect to databases in SAS Viya

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.

Discussion stats
  • 2 replies
  • 1635 views
  • 0 likes
  • 2 in conversation