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.
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
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
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.