BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AmirSari
Quartz | Level 8

Hi everyone,

 

I have the below SAS code for calculating cumulative returns. The code works fine for one period but I need to get it worked for multiple periods.

 

proc sql;
create table returns as
select *
from amirkhan.mydata
order by permno, date
;
create table cum_returns as
select permno , exp(sum(log(1+ret))) - 1 as cum_return
, min(ret) as minret , max(ret) as maxret
, n(ret) as n_periods , nmiss(ret) as n_miss
, sum(ret=.P) as n_dot_p , min(date) as first_date
, max(date) as last_date
from returns
where ('01apr1991'd <= date <= '31mar1992'd)
group by permno
;
quit;

 

This code generates the cumulative returns for the period April 01, 1991 to March 31, 1992. I need to modify the code so that it could give me the results for multiple periods. I need cumulative returns for the following periods as well:

 April 01, 1992 to March 31, 1993

April 01, 1993 to March 31, 1994

April 01, 1994 to March 31, 1995

.....

 

Thanks for your time and help.

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

Add to your data, according to dates, a period code as new variable (the fiscal_year),

then run your SQL with a light change:

 /* where ('01apr1991'd <= date <= '31mar1992'd) <<< drop this line */

   group by fiscal_year, permno

View solution in original post

2 REPLIES 2
Shmuel
Garnet | Level 18

Add to your data, according to dates, a period code as new variable (the fiscal_year),

then run your SQL with a light change:

 /* where ('01apr1991'd <= date <= '31mar1992'd) <<< drop this line */

   group by fiscal_year, permno

AmirSari
Quartz | Level 8
Thank you for your reply!
That solved the problem!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2738 views
  • 0 likes
  • 2 in conversation