09-01-2014 03:27 PM
Sorry for not responding earlier.
The time period in the sample dataset started from 1990. So, when we compute std using 24-month interval, the std observation corresponding to 1991 should be missing since we do not have 24 returns till 1991. The code returns a std for 1991 too using whatever returns are available. With proc sql, I use TRIMLEFT=23 to take care of that.
I had created the month variable in earlier dataset using the date variable.
Anyway, a sample of the original dataset is attached.
09-02-2014 09:41 AM
OK. I understood what you mean. You want all of these 24 month have data when you compute STD ?
Code is trivial changed on my original code .
proc import datafile='c:\temp\sample.csv' out=temp dbms=csv replace; guessingrows=32767; run; data have; set temp; d=mdy(month,1,year); r=input(ret,?? best32.); drop date ret; format d date9.; run; proc sql ; create table std as select *, (select std(r) from have where d between intnx('month',a.d,-36,'s') and intnx('month',a.d,-12,'s') and cusip=a.cusip having intck('month',min(d),max(d))=24) as rolling_std from have as a; quit;