BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
2 REPLIES 2
deleted_user
Not applicable
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
Cynthia_sas
SAS Super FREQ
Hi:
These Tech Support notes and the documentation link illustrate the wrong and right ways to use the LAG function. LAG only puts a value in the queue when it is called. Therefore, it is better to do your lag OUTSIDE of any condition, get a value in the queue and then deal with the manipulations using the lagged value inside your conditional logic -- but don't use the LAG function itself inside the conditional logic. For more information, refer to the documentation....or if you get stuck, you might consider working with Tech Support on this issue.

cynthia

http://support.sas.com/documentation/cdl/en/etsug/60372/HTML/default/etsug_tsdata_sect048.htm
http://support.sas.com/kb/24/665.html
http://support.sas.com/kb/25/938.html
http://support.sas.com/kb/24/694.html

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 566 views
  • 0 likes
  • 2 in conversation