obs rtrn
015 0.002
015 0.0015
015 0.01
015 -0.006
016 0.008
016 0.0014
016 0.025
016 -0.005
I want cumulative return of the rtrn keeping the first rtrn from each group intact. Please look at the example below
Cum_rtrn
0.002
(1+0.002)*(1+0.0015)-1
(1+0.002)*(1+0.0015)* (1+0.01)-1
Here's a reasonable way:
proc sort data=have; by id; run; data want; set have; by id; if first.id then cum_rtrn = rtrn; else cum_rtrn = (1 + cum_rtrn) * (1 + rtrn) - 1; retain cum_rtrn; run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Submit your idea!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.