BookmarkSubscribeRSS Feed
abdulla
Pyrite | Level 9

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

 

2 REPLIES 2
Reeza
Super User
Please post anything you've tried so far.
Astounding
PROC Star

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;