Time Series Model Package

Example 32.1 Fitting and Forecasting with ARIMA and ESM Models

The airline passenger data, given as Series G in Box and Jenkins (1976), have been used in time series analysis literature as an example of a nonstationary seasonal time series; for more information about ARIMA modeling of Series G, see "Example 7.2 Seasonal Model for the Airline Series" in the ARIMA chapter of SAS/ETS User's Guide.

This example shows how you can use the objects in the TSM package to fit the airline model, ARIMA(0,1,1) times (0,1,1)Subscript 12 NOINT and to fit the Winters exponential smoothing model to the airline series. In particular, it shows how you can do the following:

  1. Create ARIMA and ESM specifications by using the ARIMASPEC and ESMSPEC specification objects.

  2. Use these specification objects to initialize the TSM model objects.

  3. Use these TSM model objects to fit the airline model and Winters model to the airline series, and to forecast the series according to these models.

  4. Postprocess the forecast results to compute an ad hoc statistic.

  5. Output the computed results to tables.

The broad outline of the code in this example is as follows:

  1. The PROC TSMODEL statement specifies the input data set (mylib.air), a variety of output tables (mylib.airFor, mylib.airEst, and so on), and the forecast lead (12).

  2. The ID statement specifies date as the time index variable, and the INTERVAL= option indicates that the data are monthly.

  3. The VAR statement specifies the input data set variable, air, which contains the airline series.

  4. The OUTARRAYS and OUTSCALARS statements declare some output arrays and scalars that are used to store the analysis results, which are subsequently saved as tables.

  5. The REQUIRE statement specifies the TSM package, which is needed for the analysis.

  6. The statements between the SUBMIT and ENDSUBMIT statements use the TSM package objects to perform the actual analysis in your CAS session.

  7. These statements are grouped in three sections:

    • The first section does the specification, fitting, and forecasting according to the airline model. The airSpec object contains the airline specification, and the airModel object is a TSM model object that is initialized by using airSpec. After the airModel is run, the parameter estimates are collected in airEst and the forecasts are collected in airFor. The model residuals are stored in the airErr array for later processing.

    • The second section does the specification, fitting, and forecasting according to the Winters exponential smoothing model. The esmSpec object contains the Winters specification, and the esmModel object is a TSM model object that is initialized by using esmSpec. The esmModel is run, and the model residuals are stored in the esmErr array for later processing.

    • The third section computes an ad hoc statistic called nbetter, which counts the number of times the airline model residuals are smaller (in absolute size) than the Winters model. This section is included to illustrate how you can write your own custom postprocessing code to analyze the results that are produced by the TSM objects.

proc tsmodel data=mylib.air
             outobj=(airFor=mylib.airFor airEst=mylib.airEst)
             outscalar=mylib.nbetter outarray=mylib.out lead=12;
   id date interval=month;
   var air;
   outarrays esmErr airErr;   **Store residuals of ESM and ARIMA models;
   outscalars nbetter nfor;
   require tsm;
   submit;

      **Temporary work arrays used in ARIMA spec;
      array diff[2]/nosymbols;
      array ma[1]/nosymbols;

      *** Analysis based on the airline model ***;
      declare object airModel(tsm);
      declare object airSpec(arimaspec);

      **Set up the airline model spec:*;
      ** Model: log(air) ~ (0,1,1)(0,1,1)12 noint *;
      rc = airSpec.Open( );
      *** Specify differencing orders ***;
      diff[1] = 1;
      diff[2] = 12;
      rc = airSpec.SetDiff(diff,2);
      *** Specify moving average orders: q = (1)(12)  ***;
      *** Use AddMAPoly twice  for the two factors    ***;
      ma[1] = 1;
      rc = airSpec.AddMAPoly(ma);
      ma[1] = 12;
      rc = airSpec.AddMAPoly(ma);
      *** Specify NOINT             ***;
      rc = airSpec.SetOption('noint',1);
      *** Specify the log transform     ***;
      rc = airSpec.SetTransform('log');
      *** Done setting up the ARIMA model ***;
      rc = airSpec.Close( );

      *** Set up and run the airModel TSM object ***;
      rc = airModel.Initialize(airSpec);
      rc = airModel.SetY(Air);
      rc = airModel.SetOption('lead',12);
      rc = airModel.Run( );

      *** Output the airline model forecasts and estimates ***;
      declare object airFor(tsmfor);
      declare object airEst(tsmpest);
      rc = airFor.Collect(airModel);
      rc = airEst.Collect(airModel);

      ***Put the airline model residuals in airErr array;
      rc = airModel.getForecast('error',airErr);

      *** Analysis based on ESM model ***;
      declare object esmModel(tsm);
      declare object esmSpec(esmspec);
      rc = esmSpec.open( );
      rc = esmSpec.SetOption('method', 'winters');
      rc = esmSpec.close( );

      ***Set up and run the TSM object ***;
      rc = esmModel.Initialize(esmspec);
      rc = esmModel.SetY(Air);
      rc = esmModel.SetOption('lead',12);
      rc = esmModel.Run( );

      **Put the ESM model residuals in esmErr array;
      rc = esmModel.getForecast('error',esmErr);

      ***Compute an ad hoc statistic based on airErr and esmErr arrays;
      nbetter = 0;
      nfor = esmModel.nfor( );
      do t=1 to nfor;
         if airErr[t] ^= . & esmErr[t] ^= . then do;
            if abs(airErr[t]) < abs(esmErr[t])
               then nbetter = nbetter + 1;
         end;
      end;
   endsubmit;
  quit;

Output 32.1.1 shows the predictions, and Output 32.1.2 shows the parameter estimates for the airline model.

Output 32.1.1: Airline Model Predictions (Partial Output)

Airline Model Predictions

DATEPREDICTSTDUPPERLOWER
JAN1961450.416.9215484.5418.2
FEB1961426.118.8590464.2390.3
MAR1961480.124.0408528.9434.7
APR1961492.827.2405548.3441.6
MAY1961509.530.5863572.0452.1
JUN1961584.237.6514661.4513.9
JUL1961670.745.9957765.3585.1
AUG1961668.248.4237768.0578.3
SEP1961559.642.6271647.7480.7
OCT1961498.339.7181580.6425.0
NOV1961431.235.8240505.5365.2
DEC1961478.941.3484565.0403.0


Output 32.1.2: Airline Model Parameter Estimates (Partial Output)

Airline Model Parameter Estimates

_EST__STDERR__TVALUE__PVALUE_
0.37730.08204.60339.828E-6
0.57240.07807.33612.17E-11


Output 32.1.3 shows the number of times the airline model residuals are smaller than the Winters model residuals.

Output 32.1.3: Number of Times the Airline Model Residuals Are Smaller Than the Winters Model Residuals

nbetter
71.0000


Last updated: July 09, 2026