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

Hi,

I have a database with monthly observation.

Screenshot 2020-05-20 at 08.53.36.png

i want to annualize volatility and Sharpe ratio, i used this piece of code for each month:

 

proc sql;
create table sampledecember1 as
select i.*, sum(EW*ret) as EW_ret,
/*create annualized volatility*/
sum((sqrt(12)*(volatility))*100) as vol_annual,
/*create annualized return*/
sum(((1+ret)**12)-1) as ret_annual,
sum(EW*L_beta) as ex_ante_beta
from Sampledecember i
group by month_bucket;
data sampledecember1a;
set sampledecember1;
/*create annualized Sharpe ratio*/
SP_annual= sum(ret_annual/vol_annual);
by month_bucket;
run;

 

The result value are too higher. 

Is correct this code?

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

When using summary functions with group by, only the summarized columns and the group columns should be in the select, otherwise you will get a "remerge" :

proc sql;
create table sampledecember1 as
select i.month_bucket, sum(EW*ret) as EW_ret,
/*create annualized volatility*/
sum((sqrt(12)*(volatility))*100) as vol_annual,
/*create annualized return*/
sum(((1+ret)**12)-1) as ret_annual,
sum(EW*L_beta) as ex_ante_beta
from Sampledecember i
group by month_bucket;

 

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

When using summary functions with group by, only the summarized columns and the group columns should be in the select, otherwise you will get a "remerge" :

proc sql;
create table sampledecember1 as
select i.month_bucket, sum(EW*ret) as EW_ret,
/*create annualized volatility*/
sum((sqrt(12)*(volatility))*100) as vol_annual,
/*create annualized return*/
sum(((1+ret)**12)-1) as ret_annual,
sum(EW*L_beta) as ex_ante_beta
from Sampledecember i
group by month_bucket;

 

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

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
  • 1 reply
  • 692 views
  • 0 likes
  • 2 in conversation