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 the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.
Ready to level-up your skills? Choose your own adventure.