SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Calculating lead values

Accepted Solution Solved
Reply
Contributor
Posts: 45
Accepted Solution

Calculating lead values

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


Accepted Solutions
Solution
‎07-18-2016 06:49 PM
Super User
Posts: 5,509

Re: Calculating lead values

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


All Replies
Solution
‎07-18-2016 06:49 PM
Super User
Posts: 5,509

Re: Calculating lead values

A small change might be enough:

 

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

Contributor
Posts: 45

Re: Calculating lead values

Posted in reply to Astounding

Yes It worked!!! Thanks a lot!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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