Hi,
I'm a beginner sas user and having trouble using lagged variables. I'm trying to create a decay curve that switches to a linear function at some point.
Code:
DATA GEVS.EPS_Decay_Curve;
power = 0.7;
tgr = 4.5;
max_growth = 12;
max_years = 50;
do X = 1 to max_years;
Y = 1/((X+1)**power);
A = (max_growth - tgr)*Y;
Increment = lag(A) - A;
SLAmt = A/(max_years-X);
/* Define when to jump to linear decay */
if Increment
do;
if X=1 then
Switch =0;
else do;
Switch = 1;
end;
end;
else
Switch =0;
/* Calculate inc_f */
/* Store lags */
lagswitch = lag(switch);
laginc_f = lag(inc_f);
lagSLAmt = lag(SLAmt);
if switch = 0 then
inc_f = Increment;
else if switch = 1 && lagswitch = 0 then
inc_f = lagSLAmt;
else
inc_f = laginc_f;
output;
end;
drop power tgr max_growth max_years lagswitch laginc_f lagSLAmt;
run;
For some reason the inc_f is not calculating correctly. It should display 0.02967 for all values where switch=1.
Can someone help?
Jer