Sorry for not responding earlier.
This is the problem I mentioned in my earlier post
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.
Thanks!
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;
Xia Keshan
Thanks, Ksharp! I will run the codes on my data and get back to you
Reeza: Yes, I have.
Proc Expand works but in that case, you need to create an additional lag variable.
Have you looked into Proc Expand?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.