![]() | ![]() | ![]() | ![]() |
Beginning in Release 6.08 of the SAS System, PROC EXPAND in SAS/ETS software can be used to make a variety of data transformations. These transformations include: leads, lags, weighted and unweighted moving averages, moving sums, and cumulative sums, to name a few. Many new transformations were added in Release 6.12,including separate specifications for centered and backward moving averages. These new transformations made it necessary to modify the syntax for some of the transformations supported prior to Release 6.12. Examples of how to specify the syntax for centered and backward moving averages using Release 6.11 and earlier and Release 6.12 and later are given below.
PROC EXPAND can compute either a centered moving average or a backward moving average. A 5-period centered moving average is computed by averaging a total of 5 consecutive values of the series (the current period value in addition to the two immediately preceding values and two values immediately following the current value). A 5-period backward moving average is computed by averaging the current period value with the values from the 4 immediately preceding periods.
The following syntax illustrates how to use the TRANSFORM=(MOVAVE n)specification to compute a 5-period centered moving average using Release 6.11 or earlier:
PROC EXPAND OUT=MA METHOD=NONE; CONVERT X = MA_X / TRANSFORM=( MOVAVE 5 ); RUN;
To compute an n period backward moving average using Release 6.11 or earlier, make use of the TRANSFORM=(MOVAVE n LAG k) specification, where k=(n-1)/2 if n is odd or where k=(n-2)/2 if n is even. For example, the following syntax illustrates how to compute a 5-period backward moving average using Release 6.11 or earlier:
PROC EXPAND OUT=MA METHOD=NONE; CONVERT X = MA_X / TRANSFORM=(MOVAVE 5 LAG 2); RUN;
The following syntax illustrates how to use the TRANSFORM=(CMOVAVE n)specification to compute a 5-period centered moving average using Release 6.12 or later:
PROC EXPAND OUT=MA METHOD=NONE; CONVERT X = MA_X / TRANSFORM = ( CMOVAVE 5 ); RUN;
The following similar syntax illustrates how to use the TRANSFORM=(MOVAVE n)specification to compute a 5-period backward moving average using Release 6.12 or later:
PROC EXPAND OUT=MA METHOD=NONE; CONVERT X = MA_X / TRANSFORM = (MOVAVE 5); RUN;
For more information, see Transformation Operations in the EXPAND chapter of the SAS/ETS User's Guide.
If you do not have access to SAS/ETS, you can compute a moving average in the DATA step as illustrated in this sample program.
Product Family | Product | System | SAS Release | |
Reported | Fixed* | |||
SAS System | SAS/ETS | All | n/a |