Examples

FORECAST Command

The following command opens the Time Series Forecasting window with the data set name and series name filled in. The time ID variable is also filled in since the data set contains the variable DATE. The interval is filled in because the system recognizes that the observations are monthly.

   forecast data=sashelp.air var=air

The following command opens the Time Series Forecasting window with the project, data set name, series, time ID, and interval fields filled in, assuming that the project SAMPROJ was previously saved either interactively or by using unattended mode as depicted below. Previously fit models appear when the Develop Models or Manage Projects window is opened.

   forecast project=samproj

The following command runs the system in unattended mode, fitting a model automatically, storing it in the project SAMPROJ in the default catalog SASUSER.FMSPROJ, and placing the forecasts in the data set WORK.SAMPOUT.

   forecast data=sashelp.workers var=electric id=date interval=month
   project=samproj entry=forecast out=sampout

The following command assumes that a new month’s data have been added to the data set from the previous example and that an updated forecast is needed that uses the previously fit model. Time ranges are automatically updated to include the new data since the REEVAL keyword is included. Substitute REFIT for REEVAL if you want the system to reestimate the model parameters.

   forecast data=sashelp.workers var=electric id=date interval=month
   project=samproj entry=forecast out=sampout reeval

The following command opens the model viewer with the project created in the previous example and with 99 percent confidence limits in the forecast graph.

   forecast data=sashelp.workers var=electric id=date interval=month
   project=samproj entry=viewmod climit=99

The final example illustrates using unattended mode with an existing project that has been defined interactively. In this example, the goal is to add a model to the model selection list, to specify that all models in that list be fit, and that all models which are fit successfully be retained.

First open the Time Series Forecasting window and specify a new project name, WORKPROJ. Then select Develop Models, choosing SASHELP.WORKERS as the data set and MASONRY as the series. Now select Model Selection List from the Options menu. In the Model Selection List window, click Actions, then Add, and then ARIMA Model. Define the model ARIMA(0,1,0)(0,1,0)s NOINT by setting the differencing value to 1 under both ARIMA Options and Seasonal ARIMA Options. Select OK to save the model and OK to close the Model Selection List window. Now select Automatic Fit from the Options menu. In the Automatic Model Selection Options window, select All autofit models in selection list in the Models to fit radio box, select All models from the Models to keep combo box, and then click OK to close the window. Select Save Project from the File menu, and then close the Develop Models window and the Time Series Forecasting window. You now have a project with a new model added to the selection list, options set for automatic model fitting, and one series selected but no models fit.

Now enter the command:

   forecast data=sashelp.workers var=electric id=date interval=month
   project=workproj entry=forecast out=workforc

The system runs in unattended mode to update the project and create the forecast data set WORKFORC. Check the messages in the Log window to find out if the run was successful and which model was selected for forecasting. To see the forecast data set, issue the command viewtable WORKFORC. To see the contents of the project, open the Time Series Forecasting window, open the project WORKPROJ, and select Manage Projects. You will see that the variable ELECTRIC was added to the project and has a forecasting model. Select this row in the table and then select List Models from the Tools menu. You will see that all of the models in the selection list which fit successfully are there, including the new model you added to the selection list.

%FORECAST Macro

This example demonstrates the use of the %FORECAST macro to start the Time Series Forecasting System from a SAS program submitted from the Editor window. The SQL procedure is used to create a view of a subset of a products data set. Then the %FORECAST macro is used to produce forecasts.

proc sql;
   create view selprod as
   select * from products
   where type eq 'A'
   order by date;
run;

%forecast(data=selprod, var=amount, id=date, interval=day,
     entry=forecast, out=typea, project=proda, refit= );