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?
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.