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

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

The HPF Procedure

Forecasts for Variable shoes
ObsTimeForecastsStandard
Error
95% Confidence Limits
62FEB19997548.0041607.52386357.27928738.7289
63MAR19997177.1472699.44005806.27018548.0244
64APR19995497.5595780.76093967.29647027.8227
65MAY19994838.2001854.51693163.37786513.0224
66JUN19996728.4521922.52444920.33758536.5668
67JUL19996786.1094985.97384853.63628718.5826
68AUG19995853.96501045.69533804.43997903.4900
69SEP19997517.01441102.29495356.55619677.4728
70OCT19997100.24891156.23154834.07699366.4210
71NOV19997224.64491207.86184857.27939592.0106
72DEC19996357.15561257.47013892.55948821.7518
73JAN20006492.26571305.28713933.95009050.5815


Last updated: March 05, 2026