There is a dataset, i want to know how to do some calculation with using REATAIN.
New variable p_selling for 2014 to 2017, the predicted selling will be 10% more than the previous year.
New variable p_benifit for 2014 to 2017, the predicted benifit will be 5% more than the previous year.
DATA Sell;
INPUT Year Selling benifit;
DATALINES;
2013 50000 3000
2014 . .
2015 . .
2016 . .
2017 . .
;
RUN;
DATA Sell_2;
SET Sell;
/* ???????????? */
RUN;
data sell_2;
set sell;
retain _selling _benefit;
if _n_ = 1
then do;
_selling = selling;
_benefit = benifit;
end;
else do;
_selling = _selling * 1.1;
_benefit = _benefit * 1.05;
selling = _selling;
benifit = _benefit;
end;
drop _:;
end;
You need additional variables because otherwise the missing values from the dataset variables will override the retained values.
Please see this similar example: https://communities.sas.com/t5/SAS-Programming/how-to-use-loop-to-calculate-row-by-row-without-creat...
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.