This is 12 months and STD but you should be able to modify it for 3 months.
Hi, it seems that this code could not produce my desired output. Do you have any other ideas?
Here could give you a start.
After running the following code, check the frequency of each window. I think it is easy for you .
data have;
infile cards expandtabs truncover;
input Stocks $ date : ddmmyy10. A B;
format date ddmmyy10.;
cards;
ABC 01/04/2011 10 2
ABC 04/04/2011 11 5
ABC 05/04/2011 15 8
ABC 06/04/2011 17 4
ABC 28/04/2011 22 9
ABC 29/04/2011 36 10
ABC 02/05/2011 12 15
ABC 03/05/2011 15 11
XYZ 02/12/2010 6 16
XYZ 03/12/2010 6 18
XYZ 05/12/2010 6 20
XYZ 06/12/2010 6 21
XYZ 03/01/2011 8 12
XYZ 04/01/2011 8 5
XYZ 05/01/2011 8 8
XYZ 06/01/2011 8 9
;
run;
proc sql;
create table temp as
select distinct stocks,year(date) as year,month(date) as month,
mdy(calculated month,1,calculated year) as window format=mmyys7.,
intnx('month',calculated window,-2) as start format=yymmdd10.,
intnx('month',calculated window,0,'e') as end format=yymmdd10.
from have;
create table want as
select a.window,b.*
from temp as a,have as b
where a.stocks=b.stocks and b.date between a.start and a.end;
quit;
Given an average of 20 trading days per month and one observation per trading day, you want to multiply the size of your dataset by 60 3
Why?
What do you want to do with the rolling windows? If you are creating rolling window statistics (i.e. one observation per rolling window, which is 5% of the original number of observations), then there are many ways to generate them without writing all that data to disk.
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 how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.