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...
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 save with the early bird rate—just $795!
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.