The HPF Procedure
Example 2.1 Automatic Forecasting of Time Series Data
(View the complete code for this example.)
This example illustrates how the HPF procedure can be used for the automatic forecasting of time series data. Retail sales data is used for this illustration.
The following DATA step creates a data set from data recorded monthly at numerous points of sales. The data set, SALES, contains a variable DATE that represents time and a variable for each sales item. Each value of the DATE variable is recorded in ascending order, and the values of each of the other variables represent a single time series:
data sales;
format date date9.;
input date : date9. shoes socks laces dresses
coats shirts ties belts hats blouses;
datalines;
01JAN1994 3557 3718 6368.80 575 987 10.8200 15.0000 102.600 12410 15013
... more lines ...
The following HPF procedure statements automatically forecast each of the monthly time series:
proc hpf data=sales out=nextyear;
id date interval=month;
forecast _ALL_;
run;
The preceding statements automatically select the best fitting model, generate forecasts for every numeric variable in the input data set (SALES) for the next twelve months, and store these forecasts in the output data set (NEXTYEAR).
The following SGPLOT procedure statements plot the forecasts related to shoe sales:
title1 "Shoe Department Sales";
proc sgplot data=nextyear;
series x=date y=shoes / markers
markerattrs=(symbol=circlefilled) lineattrs=(pattern=1);
series x=date y=socks / markers
markerattrs=(symbol=circlefilled) lineattrs=(pattern=1);
series x=date y=laces / markers
markerattrs=(symbol=circlefilled) lineattrs=(pattern=1);
xaxis values=('01JAN1994'd to '01DEC2000'd by year);
yaxis label='item';
refline '01JAN1999'd / axis=x;
run;
The SGPLOT procedure results are shown in Output 2.1.1. The historical data is shown to the left of the vertical reference line, and the forecasts for the next twelve monthly periods is shown to the right.
Output 2.1.1: Retail Sales Forecast Plots

The following HPF procedure statements are identical to the preceding statements except that the PRINT=FORECASTS option is specified:
proc hpf data=sales out=nextyear print=forecasts;
id date interval=month;
forecast _ALL_;
run;
In addition to automatically forecasting each of the monthly time series, the preceding statements print the forecasts by using the Output Delivery System (ODS), which is partially shown in Output 2.1.2. This output shows the predictions, prediction standard errors, and the upper and lower confidence limits for the next twelve monthly periods.
Output 2.1.2: Forecast Tables
| Shoe Department Sales |
| Forecasts for Variable shoes | |||||
|---|---|---|---|---|---|
| Obs | Time | Forecasts | Standard Error | 95% Confidence Limits | |
| 62 | FEB1999 | 7548.0041 | 607.5238 | 6357.2792 | 8738.7289 |
| 63 | MAR1999 | 7177.1472 | 699.4400 | 5806.2701 | 8548.0244 |
| 64 | APR1999 | 5497.5595 | 780.7609 | 3967.2964 | 7027.8227 |
| 65 | MAY1999 | 4838.2001 | 854.5169 | 3163.3778 | 6513.0224 |
| 66 | JUN1999 | 6728.4521 | 922.5244 | 4920.3375 | 8536.5668 |
| 67 | JUL1999 | 6786.1094 | 985.9738 | 4853.6362 | 8718.5826 |
| 68 | AUG1999 | 5853.9650 | 1045.6953 | 3804.4399 | 7903.4900 |
| 69 | SEP1999 | 7517.0144 | 1102.2949 | 5356.5561 | 9677.4728 |
| 70 | OCT1999 | 7100.2489 | 1156.2315 | 4834.0769 | 9366.4210 |
| 71 | NOV1999 | 7224.6449 | 1207.8618 | 4857.2793 | 9592.0106 |
| 72 | DEC1999 | 6357.1556 | 1257.4701 | 3892.5594 | 8821.7518 |
| 73 | JAN2000 | 6492.2657 | 1305.2871 | 3933.9500 | 9050.5815 |