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.

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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
  • 1643 views
  • 0 likes
  • 3 in conversation