Thank you for your concern Richard, do you have any suggestions to improving the PERMNO and DATE order? Do you mean that these are not consecutive? This is not too much of a problem because the focus here is on average volatiles (standard deviations). My main objective is just to compare the typical size of the standard deviation two years before with two years after. Ksharp I am having difficulty with the 1st code produced actually. It appears that: "mean_two_year_after" has the same value as "mean_two_year_before". This cannot be correct. I suspect there is a problem with the code, maybe at the standard devation calculations: proc sql; create table temp as select h.*, case when h.distcd in (1262 1272) then (select std(ret) from have where permno = h.permno and date between intnx('year',-1,h.date,'s') and h.date) else . end as std_one_year_before , case when h.distcd in (1262 1272) then (select std(ret) from have where permno = h.permno and date between intnx('year',-2,h.date,'s') and h.date) else . end as std_two_year_before , case when h.distcd in (1262 1272) then (select std(ret) from have where permno = h.permno and date between h.date and intnx('year',1,h.date,'s')) else . end as std_one_year_after , case when h.distcd in (1262 1272) then (select std(ret) from have where permno = h.permno and date between h.date and intnx('year',2,h.date,'s')) else . end as std_two_year_after from test_vol as h; I see that it contains: " case when h.distcd in (1262 1272)" this worries me. I shall provide an example of what I am looking to do, if permno 10008 had 1262 on 03/07/2010... I would like to calculate permos 10008 average standard deviation for 03/07/2008 to 03/07/2010, this is known as before (note the daily standard deviations used in the mean computation do not have to be associated with their own 1262 and 1272 distcd). Then, following the same pattern, I would also like to calculate permnos 10008 average standard deviation from 03/07/2010 to 03/07/2012. If my data doesn't give me the full two years before, and after, that is OK just utilize the observations that I have. Are you sure the code above accurately does this? I have attempted to use your second code without the 1262 and 1272 but it appears that this is taking too long with my data.
... View more