BookmarkSubscribeRSS Feed
4 REPLIES 4
Reeza
Super User

https://communities.sas.com/t5/Base-SAS-Programming/standard-deviation-at-the-end-of-each-month-base...

 

This is 12 months and STD but you should be able to modify it for 3 months. 

trungcva112
Obsidian | Level 7

Hi, it seems that this code could not produce my desired output. Do you have any other ideas?

Ksharp
Super User

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;
mkeintz
PROC Star

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.

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-white.png

Our biggest data and AI event of the year.

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.

 

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 3002 views
  • 0 likes
  • 4 in conversation