BookmarkSubscribeRSS Feed
NitcanRicky
Calcite | Level 5

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;

 

2 REPLIES 2
Kurt_Bremser
Super User
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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 637 views
  • 0 likes
  • 3 in conversation