Hi, I am trying to calculate a varible in SAS which is dependant on the previously calculated varibles. I thought this would be simple with the following code but it does not compute.
data test1;
set rate;
if id_perd = '1' then Dis_fact= 1/(1+((Swap_Spot_Rate)/12));
else if id_perd > '1' then Dis_fact = (1/(1+((Swap_Spot_Rate)/12)))*lag(Dis_fact);
run;
Is it possible to calculate a varible dependant on the previously calculated varible in sas? All help would be appreciate. Thanks! Patrick B.
You can probably just RETAIN DIS_FACT instead of LAGing, and just use DIS_FACT on the right instead of LAT(DIS_FACT);
Thanks for the help!
Patrick,
It should be as easy as 1 2 3.
First, make sure that RATE does not already contain a variable named DIS_FACT.
Second, get rid of the LAG function entirely.
Third, add this statement to the DATA step:
retain dis_fact;
That should do it.
Thanks for the help!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.