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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

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