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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.