Help using Base SAS procedures

Create rolling 12 month window for daily data

Reply
Contributor
Posts: 39

Create rolling 12 month window for daily data

Hi all,

 

I used the code to create rolling window for 12 months (t-12) to calculate R2, residual... for month t .

For ex, 

01JAN2000 to 31DEC2000 -->  JAN2001

01FEB2000 to 31JAN2001 --->  FEB 2001

01MAR2000 to 31FEB2001  ---> MAR 2001     

.....

I can run with monthly data, but for DAILYdata I cannot use this code:

proc sql;
create table Form100
as select distinct a.permno, a.date as end, b.ret, b.date
from crsp3 (keep=permno date) as a, crsp3 as b
where a.permno=b.permno and 1<=intck("month", b.date, a.date)<&J and 0<=intck("year",b.date,a.date)<=1
group by a.permno, a.date;
quit;

 

Could you please me with this? THank you very much.

HA

Trusted Advisor
Posts: 1,394

Re: Create rolling 12 month window for daily data

Do you mean:

 

where a.permno=b.permno and    /*  1<=intck("month", b.date, a.date)<&J and 0<=intck("year",b.date,a.date)<=1 */

           b.date <= intnx('year',a.date,1,same)

 

what do you have in &j ? - did you assigned it a value ?

Contributor
Posts: 39

Re: Create rolling 12 month window for daily data

Yes, I did assign it J=12

Trusted Advisor
Posts: 1,394

Re: Create rolling 12 month window for daily data

have you tried change the where clause as offered ?
Contributor
Posts: 39

Re: Create rolling 12 month window for daily data

Thank you so much, I did try, but a.date just shifts one day, and I need it shift for one month. 

 

 

Trusted Advisor
Posts: 1,394

Re: Create rolling 12 month window for daily data

[ Edited ]

sorry it is not clear enough to me.

give an example by values of a.date= ...     b.date= ....    valid period from date=    to date=  

Contributor
Posts: 39

Re: Create rolling 12 month window for daily data

[ Edited ]

I mean 

 

b. date from 01JAN2000 to 31DEC2000 -->  it will be used for hold year to calculate in JAN2001 (a.date, can be 01Jan2001 or 31 jan2001, it is not important)

b. date from 01FEB2000 to 31JAN2001 --->  will be used for next month in FEB 2001 (a.date shift one month)

b. date from 01MAR2000 to 31FEB2001  ---> MAR 2001     

Super User
Posts: 17,868

Re: Create rolling 12 month window for daily data

You could also consider creating a table with the start/end dates that feed your intervals and then use that in your query when joining. 

 

 

 

 

 

Contributor
Posts: 39

Re: Create rolling 12 month window for daily data

Thank you, I am a beginner of Sas so I am trying to find how to create table as you said. But I am running daily stock return for US market, could it use for very large data.

 

 

Super User
Posts: 17,868

Re: Create rolling 12 month window for daily data

How large is your data? Do you need to add in all the data for the 12 months or are you trying to calculate some sort of statistics across the interval. Otherwise you're going to be multiplying the size of your data significantly since each record will belong to multiple intervals.

 

Also, do you have SAS/ETS? Have you looked at PROC TIMESERIES or EXPAND?

Contributor
Posts: 39

Re: Create rolling 12 month window for daily data

My data has 27.612.898 observations. I want to create to run proc preg for R2 and residual (CAPM model)  and skewness (has formula). If data is too large, I just use it for calculate one by one, if I can find solution.

 

Thank you  so much for suggestion, I am just gg search and reading how to use but I have no idea until now. 

 

Super User
Posts: 9,682

Re: Create rolling 12 month window for daily data

it is good for SQL to get ROLLING window.

code not tested.

 

proc sql;
create table Form100
as
 select a.permno, a.date as end, 

(select sum(residual) from crsp3 where permno=a.permno 
 and date between a.date and intnx('year',a.date,1,'s')-1 )
as sum_residual

from crsp3 (keep=permno date) as a

group by a.permno, a.date;
quit;
Contributor
Posts: 39

Re: Create rolling 12 month window for daily data

Thank you, I am going to check now. But I want create rolling window to calculate R2, residual (must use proc preg for regression market model) and skewness.

 

So can i combine proc preg and proc sql? and how about skewness?

 

Thank you so much,

Valued Guide
Posts: 797

Re: Create rolling 12 month window for daily data

These two papers I presented at NESUG discuss (1) how to make rolling windows of the original data, and (2) how to make rolling SSCP matrices ready for use in PROC REG.  Did you know that there is a sas data set TYPE=SSCP that proc reg accepts?  Take a look at these:

 

  1. Rolling Regressions with PROC FCMP and PROC REG
  2. Arrays Plus Data Step Plus Cramer's Rule = Fast Rolling Regressions

 

I'd probably avoid making your own implementation of Cramer's rule (I wrote that mostly as an exercise), but even so, the second paper probably provides a better guide to making the rolling TYPE=SSCP data set for to PROC REG.  Now remember, submitting an SSCP matrix means you can directly produce TOTAL residuals for each window, but not day-by-day residuals.   To do that, you'd have to take the intercept and coefficients estimates for each window and run them against your data.

 

Regards,

Mark

Contributor
Posts: 39

Re: Create rolling 12 month window for daily data

Hi Mark,

 

I really appreciate your support, I am going to find out my code based on your papers now. Hope I can do it.

 

Have a good day. 

 

Ha

Ask a Question
Discussion stats
  • 27 replies
  • 702 views
  • 6 likes
  • 5 in conversation