This example shows the use of PROC EXPAND to perform various transformations of time series. The following statements read in monthly values for a variable X.
data test; input year qtr x; date = yyq( year, qtr ); format date yyqc.; datalines; 1989 3 5238 1989 4 5289 1990 1 5375 1990 2 5443 1990 3 5514 1990 4 5527 1991 1 5557 1991 2 5615 ;
The following statements use PROC EXPAND to compute lags and leads and a 3-period moving average of the X series.
proc expand data=test out=out method=none; id date; convert x = x_lag2 / transformout=(lag 2); convert x = x_lag1 / transformout=(lag 1); convert x; convert x = x_lead1 / transformout=(lead 1); convert x = x_lead2 / transformout=(lead 2); convert x = x_movave / transformout=(movave 3); run; title "Transformed Series"; proc print data=out; run;
Because there are no missing values to interpolate and no frequency conversion, the METHOD=NONE option is used to prevent PROC EXPAND from performing unnecessary computations. Because no frequency conversion is done, all variables in the input data set are copied to the output data set. The CONVERT X; statement is included to control the position of X in the output data set. This statement can be omitted, in which case X is copied to the output data set following the new variables computed by PROC EXPAND.
The results are shown in Output 15.4.1.
Output 15.4.1: Output Data Set with Transformed Variables
Transformed Series |
Obs | date | x_lag2 | x_lag1 | x | x_lead1 | x_lead2 | x_movave | year | qtr |
---|---|---|---|---|---|---|---|---|---|
1 | 1989:3 | . | . | 5238 | 5289 | 5375 | 5238.00 | 1989 | 3 |
2 | 1989:4 | . | 5238 | 5289 | 5375 | 5443 | 5263.50 | 1989 | 4 |
3 | 1990:1 | 5238 | 5289 | 5375 | 5443 | 5514 | 5300.67 | 1990 | 1 |
4 | 1990:2 | 5289 | 5375 | 5443 | 5514 | 5527 | 5369.00 | 1990 | 2 |
5 | 1990:3 | 5375 | 5443 | 5514 | 5527 | 5557 | 5444.00 | 1990 | 3 |
6 | 1990:4 | 5443 | 5514 | 5527 | 5557 | 5615 | 5494.67 | 1990 | 4 |
7 | 1991:1 | 5514 | 5527 | 5557 | 5615 | . | 5532.67 | 1991 | 1 |
8 | 1991:2 | 5527 | 5557 | 5615 | . | . | 5566.33 | 1991 | 2 |