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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 2 replies
  • 750 views
  • 0 likes
  • 3 in conversation