Time Series Analysis Package
MOVINGSUMMARY Method
rc = TSA.MOVINGSUMMARY (y, 'method', k, <lead>, <w>, <'setmiss'>, <'abs'>, x, <p>, <nmiss>);
The MOVINGSUMMARY function computes statistics for a set of values within a moving time window.
Required Arguments
You must specify the following arguments, separated by commas:
- y
specifies the input time series array.
- 'method'
-
specifies the statistic to calculate for each output array,
, based on the elements of the y input array in the t window.
You can specify the following methods within single quotation marks:
- EWMA
calculates the exponentially weighted moving average.
- GMEAN
calculates the moving geometric mean.
- MAX
calculates the maximum value.
- MEAN
calculates the moving average.
- MED
calculates the median value.
- MIN
calculates the minimum value.
- PROD
calculates the moving product.
- RANGE
calculates the maximum value minus the minimum value.
- SUM
calculates the moving sum.
- TVALUE
calculates the standard deviation divided by the mean.
- VAR
calculates the variance of the sample defined by the window around t.
- k
specifies the window size, where k is a positive integer. When the method is EWMA, k is always set to 1, and any other value that you specify is ignored. Defaults are used for all other arguments except w. For any other method, k is a required argument, and its value should not be less than 1.
Optional Arguments
You can also specify the following arguments, separated by commas. If you want to use a default value for any of these arguments, enter a space for it.
- lead
-
specifies the number of leading terms, where lead is a nonnegative integer less than k. You can specify the following values:
- 0
specifies the backward moving summary.
- k/2
specifies the centered moving summary.
- k–1
specifies the forward moving summary.
The default value is 0. When the method is EWMA, lead is set to 0.
- w
specifies an array of weights that has k elements when k > 1, or specifies a scalar value when k = 1. When the method is EWMA, this argument must be a scalar between 0 and 1, inclusive. If you omit this value, then by default, EWMA sets w to 1, and the MEAN, PROD, TVALUE, and VAR methods do not use any weight. This argument is ignored for the GMEAN, MED, MIN, RANGE, and SUM methods.
- 'setmiss'
-
specifies how missing values are interpreted.
You can specify the following values within single quotation marks:
- IGNORE
specifies that missing values have no effect on the summary.
- MEAN
specifies that missing values are replaced with the mean of the remaining nonmissing values in the window. This value is supported only for the SUM method.
- MISSING
specifies that if the input window contains a missing value, the output value is also missing.
The default value is IGNORE. When the method is EWMA, 'setmiss' is always set to IGNORE, and any other value that you specify is ignored.
- 'abs'
-
specifies how the series is transformed into nonnegative values prior to performing the moving summary.
You can specify the following values within single quotation marks:
- OFF
specifies no modification. This value is not supported for the GMEAN method, because the geometric mean is undefined for negative values in the series.
- ON
transforms each member of the series into its absolute value.
- SQUARE
transforms each member of the series into its square.
The default value is ON when the method is GMEAN and is OFF for any other method. When the method is EWMA, 'abs' is always set to OFF, and any other value that you specify is ignored.
Returned Values
The MOVINGSUMMARY function returns the following values:
- rc
-
returns one of the following scalar return codes:
rc Termination Reason 4 Warping limits relaxed 3 Expansion limits relaxed 2 Compression limits relaxed 1 Warping limits imposed 0 Success < 0 Computational failure - x
returns the transformed series.
Optional Returned Values
You can also specify the following arguments, separated by commas, to request additional returned values. If you do not want the value to be returned, enter a space for it.
- p
returns an array in which element t is the number of products that contributed to element t of x. The p argument is supported only when method is PROD or GMEAN.
- nmiss
returns the number of missing values that are generated.
Examples
This example uses the TSMODEL procedure to compute the five-period moving average of the time series array Air:
proc tsmodel data=mylib.air outscalar=mylib.scalars outarray=mylib.arrays;
id date interval=month;
var air;
outarrays x p;
outscalars rc nmiss;
require tsa;
submit;
declare object TSA(tsa);
rc=TSA.MOVINGSUMMARY(air, 'MEAN' , 5, 0 , , , , x, p, nmiss);
endsubmit;
run;
This example uses the TSMODEL procedure to compute the five-period centered weighted moving product of the time series array Air:
proc tsmodel data=mylib.air outscalar=mylib.scalars outarray=mylib.arrays;
id date interval=month;
var air;
outarrays x;
outscalars rc;
require tsa;
submit;
declare object TSA(tsa);
Array w[5]/nosymbols; w[1]=0.3; w[2]=0.2; w[3]=0.25; w[4]=0.1; w[5]=0.15;
rc=TSA.MOVINGSUMMARY(air, 'PROD' , 5, 2.5 , w, , , x, , );
endsubmit;
run;