SAS/ETS Examples
Transforming the Frequency of Time Series Data
Transforming the Frequency of Time Series Data
Contents |
Back to Example
/* Transforming the Frequency of Time-Series Data */
/* Changing Frequency */
data monthly;
set sashelp.citimon;
keep date fm1;
run;
data quarter;
set sashelp.citiqtr;
keep date gdp;
run;
data weekly;
set sashelp.citiwk;
keep date wspglt;
run;
proc expand data=quarter out=temp1 from=qtr to=month;
id date;
convert gdp / observed = total;
run;
proc expand data=weekly out=temp2 from=week to=month;
id date;
convert wspglt = interest / observed = average;
run;
data combined;
merge monthly temp1 temp2;
by date;
if interest=. then delete;
run;
title "Combined Data Set (first 5 observations)";
proc print data=combined (obs=5);
run;
/* Interpolating Irregular Observations */
data samples;
input date : date. defects @@;
label defects = "Defects per 1000 units";
format date date.;
datalines;
13jan92 55 27jan92 73 19feb92 84 8mar92 69
27mar92 66 5apr92 77 29apr92 63 11may92 81
25may92 89 7jun92 94 23jun92 105 11jul92 97
15aug92 112 29aug92 89 10sep92 77 27sep92 82
;
title "Sampled Defect Rates";
proc print data=samples;
run;
proc expand data=samples out=monthly to=month;
id date;
convert defects / observed=(beginning,average);
run;
title "Estimated Monthly Average Defect Rates";
proc print data=monthly;
run;
proc expand data=samples out=daily to=day;
id date;
convert defects = interpol;
run;
data daily;
merge daily samples;
by date;
run;
proc gplot data=daily;
plot interpol*date defects*date / vaxis=axis2 overlay cframe=ligr;
title1 "Plot of Interpolated Defect Rate Curve";
axis2 label=(angle=90);
symbol1 c=blue interpol=join value=none;
symbol2 c=red interpol=none value=star;
run;
quit;