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
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 ?
Yes, I did assign it J=12
Thank you so much, I did try, but a.date just shifts one day, and I need it shift for one month.
sorry it is not clear enough to me.
give an example by values of a.date= ... b.date= .... valid period from date= to date=
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
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.
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.
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?
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.
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;
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,
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:
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
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
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.