could some one please let me know how to adjust the following code to calculate WEEKLY VARIANCE ? the code below does it for monthly variance.
Data set is attached.
infile "F:\data\residuals.csv" DSD MISSOVER;
input date :MMDDYY9. lnprices residual;
format date mmddyy10.;
/* calculate monthly variance for all variables;*/
proc summary data=test nway;
output out=month_var (drop=_:) var= ;
format date monyy.;
/* rearrange data for by-group processing in GPLOT;*/
proc transpose data=month_var out=tmonth_var (rename=(col1=var));
format date monyy.;
proc sort data=tmonth_var;
by _name_ date;
goptions ftext='Arial' htext=2 gunit=pct;
symbol1 v=dot i=join;
axis1 label=(angle=90 "Monthly Variance");
title h=4 "Variance by Month for:1997-2005";
footnote j=right "Source: Henry Hub";
proc gplot data=tmonth_var;
by _name_ ;
Change the format applied to your data to be a weekly format rather than monyy., I aligned mine to the beginning of the week but something similar can be done for end of the week if required.
%do k=0 %to 3000;
%eval(2+&k*7) - %eval(2+&k*7+6)=%sysfunc(putn(%eval(2+&k*7), date.))
%end;;*need two semicolons to end properly;
I had some help with creating one here, see code above.
Or a custom format using the date directives such as:
proc format library=work;
picture MyWeekFmt (min=8 max=8)
low-high = '%Y %0U' (datatype=date);
Note that the directives ARE CASE SENSITIVE. The U could be W or V for different definitions of start week.
put x= MyWeekFmt.;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.