I have a table where the primary id is permno (company identifier). The table also contains year and weekly returns over that year. Finally, it has a column named 'rret' which is 1 when the weekly return is greater than average yearly return (upweek), otherwise 0 (downweek).
I want to calculate standard deviation of weekly return for upweek and downweek for a company in a given year and then calculate ratio between two. So far, I have just calculated standard deviation of weekly return using the following code (for upweek and downweek):
proc sql;
create table crash.duvol5 as
select permno, fyear, rret, std(weekly_ret) as stdret
from crash.duvol4
group by permno, fyear, rret
;
quit;
Basically, I want this in another column:
I am not sure how to calculate it with SQL. Any help will be appreciated. Thanks in advance.