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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

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
  • 802 views
  • 0 likes
  • 3 in conversation