The EXPAND Procedure

Example 15.4 Using Transformations

(View the complete code for this example.)

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

Obsdatex_lag2x_lag1xx_lead1x_lead2x_movaveyearqtr
11989:3..5238528953755238.0019893
21989:4.52385289537554435263.5019894
31990:1523852895375544355145300.6719901
41990:2528953755443551455275369.0019902
51990:3537554435514552755575444.0019903
61990:4544355145527555756155494.6719904
71991:15514552755575615.5532.6719911
81991:2552755575615..5566.3319912


Last updated: November 05, 2018