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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: