BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rawagah
Obsidian | Level 7

Hello,

 

I have this dataset:

 

YearAmount
20161000
20172000
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:

YearAmountExpected 
201610001000
201720002000
2018.100
2019.5
2020.0.25
2021.0.0125

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data want;
    set have;
    retain expected;
    if not missing(amount) then expected=amount;
    else expected=expected*0.05;
run;
--
Paige Miller

View solution in original post

1 REPLY 1
PaigeMiller
Diamond | Level 26
data want;
    set have;
    retain expected;
    if not missing(amount) then expected=amount;
    else expected=expected*0.05;
run;
--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 1201 views
  • 1 like
  • 2 in conversation