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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Save the date!
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.