Univariate Time Series Analysis Action Set
Forecasting Time Series Data Using the ARIMA Model
This section contains PROC CAS code.
Note: Input data must be accessible in your CAS session, either as a CAS table or as a transient-scope table. A CAS table has a two-level name: the first level is your CAS engine libref, and the second level is the table name. You refer to this table in the CAS procedure by specifying only the second level. For more information about two-level names, see Chapter 4, Shared Concepts (SAS Econometrics: Econometrics Procedures). A transient-scope table is called directly from the action and exists in memory for the duration of the action. For more information about accessing data, see SAS Viya: System Programming Guide. For more information about PROC CAS and programming in CASL, see SAS Cloud Analytic Services: CASL Programmer’s Guide and SAS Cloud Analytic Services: CASL Reference.
This example illustrates how you can use the arima action to model and forecast the airline passengers time series data.
The following DATA step creates the data table mycas.air in your CAS session from data that were recorded monthly. This DATA step assumes that your CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.
data mycas.myair;
set sashelp.air;
AIR2 = air*air;
run;
The data table, mycas.myair, contains a variable, date (which represents time) and two variables named air and air2 (which represent the monthly number of passengers and their square, respectively). Each value of the date variable is recorded in ascending order.
The following PROC CAS statements use the arima action in the uniTimeSeries action set to specify an ARIMA model without a mean term to the logarithms of the airline passenger numbers, and an ARIMA
model without a mean term to the squared airline passenger numbers:
proc cas;
uniTimeSeries.arima /
table={name='MYAIR'},
timeId={name='DATE'},
interval='MONTH',
outEst={name='ARIEST', replace=true},
outFor={name='ARIFOR', replace=true},
series={{name='AIR',
model={{estimate={q={{factor={1}}, {factor={12}}},
method='ML', diff={1, 12},
noint=true, transform='log'},
forecast={{lead=4}}}}
},
{name='AIR2',
model={{estimate={p={{factor=1}},
method='ML', noint=true,
diff={1}, transform='log'},
forecast={{lead=6}}}}
}
};
run;
table.fetch /
table = {name='ARIFOR',
where='date>=''01SEP1960''d'};
run;
quit;
The table parameter names the input data table to be analyzed. The timeId parameter specifies that the Date variable contains time ID values. The interval parameter specifies a monthly interval at which to accumulate the time series vectors. The outEst parameter specifies the table in which to store the parameter estimates and their standard errors. The outFor parameter specifies the table in which to store the forecasts for the accumulated time series variables.
The series parameter list contains the name parameter (which names the series you want to analyze) and the model parameter list (which the specifies the types of inference tasks you want to perform).
Each model parameter list contains estimate and forecast parameter lists:
The
estimateparameter list contains several parameters related to estimation tasks. For example, the parametersp(in the firstmodelparameter list),q(in the secondmodelparameter list), anddiffspecify the AR, MA, and difference orders, respectively, in the ARIMA model, and the parametersmethodandtransformspecify the estimation method and type of transform you want to use. Finally the parameternointspecifies a model without an intercept term.The
forecastparameter list contains the parameterlead, which specifies the number of steps you want to forecast in the future.
The arima action saves the parameter estimates and the forecasts to output tables whose names are specified in the outEst and outFor parameters. Output 21.1.1 shows a selected part of the ARIFOR table, which is requested in the outFor parameter.
Output 21.1.1: Selected Rows of Forecasts of Sales of Shoes
| Selected Rows from Table ARIFOR | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| _Index_ | Variable Name | Forecasting Model | Time ID Values | Actual Values | Predicted Values | Prediction Errors | Prediction Standard Errors | Upper Confidence Limits | Lower Confidence Limits |
| 1 | AIR | arimaModel1_1 | SEP1960 | 508 | 513.30550748 | -5.305507482 | 18.998904474 | 551.53524047 | 477.07210737 |
| 2 | AIR | arimaModel1_1 | OCT1960 | 461 | 447.90233346 | 13.097666539 | 16.578146002 | 481.26099875 | 416.28563692 |
| 3 | AIR | arimaModel1_1 | NOV1960 | 390 | 401.01137708 | -11.01137708 | 14.842577636 | 430.87771915 | 372.70463682 |
| 4 | AIR | arimaModel1_1 | DEC1960 | 432 | 438.8158222 | -6.815822201 | 16.241828241 | 471.49774646 | 407.8405277 |
| 5 | AIR | arimaModel1_1 | JAN1961 | . | 450.73196198 | . | 16.682878644 | 484.30137104 | 418.91552657 |
| 6 | AIR | arimaModel1_1 | FEB1961 | . | 426.11293231 | . | 18.379312587 | 463.25326816 | 391.22240831 |
| 7 | AIR | arimaModel1_1 | MAR1961 | . | 479.56635127 | . | 23.25334202 | 526.72972214 | 435.60183908 |
| 8 | AIR | arimaModel1_1 | APR1961 | . | 493.10515339 | . | 26.287883208 | 546.59972273 | 443.58529259 |
| 9 | AIR2 | arimaModel1_1 | SEP1960 | 258064 | 371376.01282 | -113312.0128 | 78612.342819 | 547653.5971 | 241037.9033 |
| 10 | AIR2 | arimaModel1_1 | OCT1960 | 212521 | 245342.54462 | -32821.54462 | 51933.75867 | 361796.99939 | 159237.13569 |
| 11 | AIR2 | arimaModel1_1 | NOV1960 | 152100 | 208736.58796 | -56636.58796 | 44185.062161 | 307815.63509 | 135478.40401 |
| 12 | AIR2 | arimaModel1_1 | DEC1960 | 186624 | 145146.54109 | 41477.458906 | 30724.412061 | 214041.89445 | 94205.917262 |
| 13 | AIR2 | arimaModel1_1 | JAN1961 | . | 198945.50943 | . | 42112.500671 | 293377.11673 | 129123.60198 |
| 14 | AIR2 | arimaModel1_1 | FEB1961 | . | 207163.24822 | . | 69797.879731 | 373318.37931 | 103240.33161 |
| 15 | AIR2 | arimaModel1_1 | MAR1961 | . | 214732.59496 | . | 94125.387014 | 447280.19913 | 86474.695477 |
| 16 | AIR2 | arimaModel1_1 | APR1961 | . | 222370.9129 | . | 117147.36242 | 518983.98341 | 74581.494746 |
| 17 | AIR2 | arimaModel1_1 | MAY1961 | . | 230236.89443 | . | 139915.82035 | 590379.73323 | 65572.021799 |
| 18 | AIR2 | arimaModel1_1 | JUN1961 | . | 238371.75984 | . | 163024.36956 | 662533.26617 | 58432.662125 |
Forecasting Time Series Data Using the ARIMA Model
This example is not available for the Lua programming language.
Forecasting Time Series Data Using the ARIMA Model
This example is not available for the Python programming language.
Forecasting Time Series Data Using the ARIMA Model
This example is not available for the R programming language.