The X12 Procedure

Example 38.9 Creating an MDLINFO= Data Set for Use with the PICKMDL Statement

This example illustrates how you can create a data set for use in the PICKMDL statement that contains five commonly used ARIMA models:

  • ARIMA (0 1 1)(0 1 1)s

  • ARIMA (0 1 2)(0 1 1)s

  • ARIMA (2 1 0)(0 1 1)s

  • ARIMA (0 2 2)(0 1 1)s

  • ARIMA (2 1 2)(0 1 1)s

The following macro code creates a MDLINFOIN= data set for a general ARIMA model:


   %macro makemodel(name,p,d,q,sp,sd,sq,model);
      data "&name" (keep= _MODELTYPE_ _MODELPART_ _COMPONENT_ 
                          _DSVAR_ _PARMTYPE_ _FACTOR_ _LAG_
                            _LABEL_ );
         length _MODELTYPE_ _MODELPART_ _COMPONENT_ _DSVAR_ 
                _PARMTYPE_ $32;
         length _FACTOR_ _LAG_ 8;
         length _LABEL_ $32;

         _MODELTYPE_="ARIMA";
         _MODELPART_="FORECAST";
         _DSVAR_=".";
     
         _LABEL_="("||"&p"||" "||"&d"||" "||"&q"||")("||
                 "&sp"||" "||"&sd"||" "||"&sq"||")s";
          
         /* nonseasonal AR factors */
         _COMPONENT_="NONSEASONAL";
         _PARMTYPE_="AR";
         _FACTOR_=1;
         do _LAG_=1 to &p;
            output;
            end;
          
         /* seasonal AR factors */
         _COMPONENT_="SEASONAL";
         _PARMTYPE_="AR";
         _FACTOR_=2;
         do _LAG_=1 to &sp;
            output;
            end;
          
         /* nonseasonal MA factors */
         _COMPONENT_="NONSEASONAL";
         _PARMTYPE_="MA";
         _FACTOR_=1;
         do _LAG_=1 to &q;
            output;
            end;
          
         /* seasonal MA factors */
         _COMPONENT_="SEASONAL";
         _PARMTYPE_="MA";
         _FACTOR_=2;
         do _LAG_=1 to &sq;
            output;
            end;
          
         /* nonseasonal DIF */
         _COMPONENT_="NONSEASONAL";
         _PARMTYPE_="DIF";
         _FACTOR_=1;
         _LAG_=1;
         do i_=1 to &d;
            output;
            end;
          
         /* seasonal DIF */
         _COMPONENT_="SEASONAL";
         _PARMTYPE_="DIF";
         _FACTOR_=2;
         _LAG_=1;
         do i_=1 to &sd;
            output;
            end;
          
      run; 
      data sasuser.&name;
        length _MODEL_ $32;
        set "&name";
        _MODEL_ = "&model";
      run;

   %mend makemodel;

The following SAS statements use the macro to generate a data set with some commonly used models for use in the PICKMDL statement:

%makemodel(x12mdl1,0,1,1,0,1,1,Model1); 
%makemodel(x12mdl2,0,1,2,0,1,1,Model2); 
%makemodel(x12mdl3,2,1,0,0,1,1,Model3); 
%makemodel(x12mdl4,0,2,2,0,1,1,Model4); 
%makemodel(x12mdl5,2,1,2,0,1,1,Model5);

data Models;
   length _NAME_ $32;
   set sasuser.x12mdl1 sasuser.x12mdl2 sasuser.x12mdl3
       sasuser.x12mdl4 sasuser.x12mdl5;
   _NAME_ = 'sales';
 run;

The Models data set is shown in Output 38.9.1.

title '5 Commonly Used Models';
proc print data=Models;
run ;

Output 38.9.1: A Data Set That Contains Models for Use with the PICKMDL Statement

5 Commonly Used Models

Obs _NAME_ _MODEL_ _MODELTYPE_ _MODELPART_ _COMPONENT_ _DSVAR_ _PARMTYPE_ _FACTOR_ _LAG_ _LABEL_
1 sales Model1 ARIMA FORECAST NONSEASONAL . MA 1 1 (0 1 1)(0 1 1)s
2 sales Model1 ARIMA FORECAST SEASONAL . MA 2 1 (0 1 1)(0 1 1)s
3 sales Model1 ARIMA FORECAST NONSEASONAL . DIF 1 1 (0 1 1)(0 1 1)s
4 sales Model1 ARIMA FORECAST SEASONAL . DIF 2 1 (0 1 1)(0 1 1)s
5 sales Model2 ARIMA FORECAST NONSEASONAL . MA 1 1 (0 1 2)(0 1 1)s
6 sales Model2 ARIMA FORECAST NONSEASONAL . MA 1 2 (0 1 2)(0 1 1)s
7 sales Model2 ARIMA FORECAST SEASONAL . MA 2 1 (0 1 2)(0 1 1)s
8 sales Model2 ARIMA FORECAST NONSEASONAL . DIF 1 1 (0 1 2)(0 1 1)s
9 sales Model2 ARIMA FORECAST SEASONAL . DIF 2 1 (0 1 2)(0 1 1)s
10 sales Model3 ARIMA FORECAST NONSEASONAL . AR 1 1 (2 1 0)(0 1 1)s
11 sales Model3 ARIMA FORECAST NONSEASONAL . AR 1 2 (2 1 0)(0 1 1)s
12 sales Model3 ARIMA FORECAST SEASONAL . MA 2 1 (2 1 0)(0 1 1)s
13 sales Model3 ARIMA FORECAST NONSEASONAL . DIF 1 1 (2 1 0)(0 1 1)s
14 sales Model3 ARIMA FORECAST SEASONAL . DIF 2 1 (2 1 0)(0 1 1)s
15 sales Model4 ARIMA FORECAST NONSEASONAL . MA 1 1 (0 2 2)(0 1 1)s
16 sales Model4 ARIMA FORECAST NONSEASONAL . MA 1 2 (0 2 2)(0 1 1)s
17 sales Model4 ARIMA FORECAST SEASONAL . MA 2 1 (0 2 2)(0 1 1)s
18 sales Model4 ARIMA FORECAST NONSEASONAL . DIF 1 1 (0 2 2)(0 1 1)s
19 sales Model4 ARIMA FORECAST NONSEASONAL . DIF 1 1 (0 2 2)(0 1 1)s
20 sales Model4 ARIMA FORECAST SEASONAL . DIF 2 1 (0 2 2)(0 1 1)s
21 sales Model5 ARIMA FORECAST NONSEASONAL . AR 1 1 (2 1 2)(0 1 1)s
22 sales Model5 ARIMA FORECAST NONSEASONAL . AR 1 2 (2 1 2)(0 1 1)s
23 sales Model5 ARIMA FORECAST NONSEASONAL . MA 1 1 (2 1 2)(0 1 1)s
24 sales Model5 ARIMA FORECAST NONSEASONAL . MA 1 2 (2 1 2)(0 1 1)s
25 sales Model5 ARIMA FORECAST SEASONAL . MA 2 1 (2 1 2)(0 1 1)s
26 sales Model5 ARIMA FORECAST NONSEASONAL . DIF 1 1 (2 1 2)(0 1 1)s
27 sales Model5 ARIMA FORECAST SEASONAL . DIF 2 1 (2 1 2)(0 1 1)s


The following statements specify that the PICKMDL method be used to choose a model from the list of models that are defined in the Models data set. The default METHOD=FIRST option is used to select the model. The chosen model is shown in the mdlchosen data set in Output 38.9.2.

proc x12 data=sales date=date mdlinfoin=Models mdlinfoout=mdlchosen;
   var sales;
   transform function=log;
   pickmdl method=first;
run;
title 'Chosen Model';
proc print data=mdlchosen;
run ;

Output 38.9.2: The Model Chosen from the Five Commonly Used Models

Chosen Model

Obs _NAME_ _MODEL_ _MODELTYPE_ _MODELPART_ _COMPONENT_ _PARMTYPE_ _DSVAR_ _VALUE_ _FACTOR_ _LAG_ _SHIFT_ _NOEST_ _EST_ _STDERR_ _TVALUE_ _PVALUE_ _STATUS_ _SCORE_ _LABEL_
1 sales MODEL1 ARIMA FORECAST TRANSFORM LOG sales . . . . . . . . . .   (0 1 1)(0 1 1)s
2 sales MODEL1 ARIMA FORECAST NONSEASONAL DIF sales . . 1 . . . . . . .   (0 1 1)(0 1 1)s
3 sales MODEL1 ARIMA FORECAST SEASONAL DIF sales . . 1 . . . . . . .   (0 1 1)(0 1 1)s
4 sales MODEL1 ARIMA FORECAST NONSEASONAL MA sales . 1 1 . 0 0.40181 0.078870 5.09458 .000001192 .   (0 1 1)(0 1 1)s
5 sales MODEL1 ARIMA FORECAST SEASONAL MA sales . 2 1 . 0 0.55695 0.076255 7.30369 2.4359E-11 .   (0 1 1)(0 1 1)s


The following statements reverse the order of the models in the input data set. The default METHOD=FIRST option is used to select the model. The chosen model is shown in the mdlchosen data set in Output 38.9.3. With METHOD=FIRST, a different model is chosen because the order is changed.

data Models;
   length _NAME_ $32;
   set sasuser.x12mdl5 sasuser.x12mdl4 sasuser.x12mdl3
       sasuser.x12mdl2 sasuser.x12mdl1 ;
   _NAME_ = 'sales';
 run;
 
 proc x12 data=sales date=date mdlinfoin=Models mdlinfoout=mdlchosen;
   var sales;
   transform function=log;
   pickmdl method=first;
run;
title 'Chosen Model';
proc print data=mdlchosen;
run ;

Output 38.9.3: The Model Chosen from the Five Commonly Used Models, Reversed Order

Chosen Model

Obs _NAME_ _MODEL_ _MODELTYPE_ _MODELPART_ _COMPONENT_ _PARMTYPE_ _DSVAR_ _VALUE_ _FACTOR_ _LAG_ _SHIFT_ _NOEST_ _EST_ _STDERR_ _TVALUE_ _PVALUE_ _STATUS_ _SCORE_ _LABEL_
1 sales MODEL3 ARIMA FORECAST TRANSFORM LOG sales . . . . . . . . . .   (2 1 0)(0 1 1)s
2 sales MODEL3 ARIMA FORECAST NONSEASONAL DIF sales . . 1 . . . . . . .   (2 1 0)(0 1 1)s
3 sales MODEL3 ARIMA FORECAST SEASONAL DIF sales . . 1 . . . . . . .   (2 1 0)(0 1 1)s
4 sales MODEL3 ARIMA FORECAST NONSEASONAL AR sales . 1 1 . 0 -0.36159 0.086055 -4.20188 0.00005 .   (2 1 0)(0 1 1)s
5 sales MODEL3 ARIMA FORECAST NONSEASONAL AR sales . 1 2 . 0 -0.06366 0.086141 -0.73905 0.46120 .   (2 1 0)(0 1 1)s
6 sales MODEL3 ARIMA FORECAST SEASONAL MA sales . 1 1 . 0 0.56109 0.072814 7.70588 0.00000 .   (2 1 0)(0 1 1)s


The following example shows the use of PICKMDL statement option METHOD=BEST to select the model. The chosen model is shown in the mdlchosen data set in Output 38.9.4. With METHOD=BEST, a different model is chosen than either of the previous models chosen. Because the order in which the models occur in the MDLINFOIN= data set affects model selection when METHOD=FIRST is specified, it is a common practice to list models from the simplest model to the most complex in the MDLINFOIN= data set that is used in conjunction with the PICKMDL statement.

 proc x12 data=sales date=date mdlinfoin=Models mdlinfoout=mdlchosen;
   var sales;
   transform function=log;
   pickmdl method=best;
run;
title 'Chosen Model';
proc print data=mdlchosen;
run ;

Output 38.9.4: The Model Chosen from the Five Commonly Used Models, METHOD=BEST

Chosen Model

Obs _NAME_ _MODEL_ _MODELTYPE_ _MODELPART_ _COMPONENT_ _PARMTYPE_ _DSVAR_ _VALUE_ _FACTOR_ _LAG_ _SHIFT_ _NOEST_ _EST_ _STDERR_ _TVALUE_ _PVALUE_ _STATUS_ _SCORE_ _LABEL_
1 sales MODEL2 ARIMA FORECAST TRANSFORM LOG sales . . . . . . . . . .   (0 1 2)(0 1 1)s
2 sales MODEL2 ARIMA FORECAST NONSEASONAL DIF sales . . 1 . . . . . . .   (0 1 2)(0 1 1)s
3 sales MODEL2 ARIMA FORECAST SEASONAL DIF sales . . 1 . . . . . . .   (0 1 2)(0 1 1)s
4 sales MODEL2 ARIMA FORECAST NONSEASONAL MA sales . 1 1 . 0 0.39613 0.086126 4.59937 0.00001 .   (0 1 2)(0 1 1)s
5 sales MODEL2 ARIMA FORECAST NONSEASONAL MA sales . 1 2 . 0 0.03961 0.086163 0.45966 0.64652 .   (0 1 2)(0 1 1)s
6 sales MODEL2 ARIMA FORECAST SEASONAL MA sales . 2 1 . 0 0.55903 0.076446 7.31277 0.00000 .   (0 1 2)(0 1 1)s