Hi, I am trying to create a waterfall in which I need subtract a value of a var1 in previous row from value of var2 of the current row.
For example
Id var1 var2 result
1 50 50 .
2 45 5 50-5= 45
3 30 15 45-15=30
4 20 10 30-10=20
Is it possible to do so in proc report... If so then how?
Thanks in advance.
Easy in a DATA step using the LAG() function.
I'm not sure it can be done in PROC REPORT, but you can always do the math in the DATA step and then use PROC REPORT on the results.
Create a view:
data have ;
input Id var1 var2 ;
cards ;
1 50 50
2 45 5
3 30 15
4 20 10
;
run ;
data v / view = v ;
set have ;
_n_ = lag (var1) ;
if nmiss (_n_) then result = _n_ ;
else result = _n_ - var2 ;
run ;
and then run your proc REPORT against the view V as input.
Kind regards
Paul D.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.