Help using Base SAS procedures

Rolling std

Reply
Contributor
Posts: 52

Rolling std

:

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!

Attachment
Super User
Posts: 10,020

Re: Rolling std

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

Contributor
Posts: 52

Re: Rolling std

Thanks, Ksharp! I will run the codes on my data and get back to you Smiley Happy

Reeza: Yes, I have.

Proc Expand works but in that case, you need to create an additional lag variable.

Super User
Posts: 19,771

Re: Rolling std

Have you looked into Proc Expand?

Ask a Question
Discussion stats
  • 3 replies
  • 258 views
  • 0 likes
  • 3 in conversation