Hello,
I have this dataset:
| Year | Amount |
| 2016 | 1000 |
| 2017 | 2000 |
| 2018 | . |
| 2019 | . |
| 2020 | . |
| 2021 | . |
and I want to do a calculation on a row level because the output of the calculation in 2018 for example depends on the output from 2017 and so on. For simplicity let's say I want to add column (Expected), which will be = this year's Amount if this year's Amount is not Null, otherwise it will be the output of last years (Expected) * 0.05.
so it will be like this:
| Year | Amount | Expected |
| 2016 | 1000 | 1000 |
| 2017 | 2000 | 2000 |
| 2018 | . | 100 |
| 2019 | . | 5 |
| 2020 | . | 0.25 |
| 2021 | . | 0.0125 |
data want;
set have;
retain expected;
if not missing(amount) then expected=amount;
else expected=expected*0.05;
run;
data want;
set have;
retain expected;
if not missing(amount) then expected=amount;
else expected=expected*0.05;
run;
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 lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.