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

Hello all, I have the data looks like this:

 

data have;
input id year xrd;
datalines;
1 1991 10
1 1992 95
1 1993 100
1 1994 20
2 1994 115
2 1995 120
2 1996 100
2 1997 110
3 1992 950
3 1993 105
3 1994 112
3 1995 120
;
run;

I want to create a new variable X=0.85*Lag(X)+ xrd, and the initial X for each id is set equal the xrd in the first year divided by 0.15, for example, X for id=1 in 1991(first year for id=1) is calculated as 10/0.15=66.66667, X for id=1 in 1992(second year for id=1) is calculated as 66.66667*0.85+ 95= 151.6667;

 

similarly, X for id=2 in 1994(first year for id=2) is calculated as 115/0.15=766.66667, X for id=2 in 1995(second year for id=2) is calculated as 766.66667*0.85 + 120= 771.667.

 

so eventually I want to have data look like this:

 

id year xrd X
1 1991 10 66.66667
1 1992 95 151.6667
1 1993 100 228.9167
1 1994 20 214.5792
2 1994 115 766.6667
2 1995 120 771.6667
2 1996 100 755.9167
2 1997 110 752.5292
3 1992 950 6333.333
3 1993 105 5488.333
3 1994 112 4777.083
3 1995 120 4180.521

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

HI @aj_goodnews 

 



data have;
input id year xrd;
datalines;
1 1991 10
1 1992 95
1 1993 100
1 1994 20
2 1994 115
2 1995 120
2 1996 100
2 1997 110
3 1992 950
3 1993 105
3 1994 112
3 1995 120
;
run;


data want;
 set have;
 by id;
 if first.id then x=xrd/0.15;
 else X=0.85*_iorc_+ xrd;
 _iorc_=x;
run;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

HI @aj_goodnews 

 



data have;
input id year xrd;
datalines;
1 1991 10
1 1992 95
1 1993 100
1 1994 20
2 1994 115
2 1995 120
2 1996 100
2 1997 110
3 1992 950
3 1993 105
3 1994 112
3 1995 120
;
run;


data want;
 set have;
 by id;
 if first.id then x=xrd/0.15;
 else X=0.85*_iorc_+ xrd;
 _iorc_=x;
run;

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 Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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