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!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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