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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.