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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 735 views
  • 1 like
  • 2 in conversation