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!
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;
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;
Thank you!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: