Creating Default MLDINFO= Data Sets for Use with the PICKMDL statement

/*--------------------------------------------------------------

                    SAS Sample Library

        Name: x13ex09.sas
 Description: Example program from SAS/ETS User's Guide,
              The X13 Procedure
       Title: Creating Default MLDINFO= Data Sets for Use with the PICKMDL statement
     Product: SAS/ETS Software
        Keys: seasonal adjustment of time series
        PROC: X13
       Notes:

--------------------------------------------------------------*/


   %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;

%makemodel(x13mdl1,0,1,1,0,1,1,Model1);
%makemodel(x13mdl2,0,1,2,0,1,1,Model2);
%makemodel(x13mdl3,2,1,0,0,1,1,Model3);
%makemodel(x13mdl4,0,2,2,0,1,1,Model4);
%makemodel(x13mdl5,2,1,2,0,1,1,Model5);

data Models;
   length _NAME_ $32;
   set sasuser.x13mdl1 sasuser.x13mdl2 sasuser.x13mdl3
       sasuser.x13mdl4 sasuser.x13mdl5;
   _NAME_ = 'sales';
run;

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

data sales;
   set sashelp.air;
   sales = air;
   date = intnx( 'month', '01sep78'd, _n_-1 );
   format date monyy.;
run;

proc x13 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 ;

data Models;
   length _NAME_ $32;
   set sasuser.x13mdl5 sasuser.x13mdl4 sasuser.x13mdl3
       sasuser.x13mdl2 sasuser.x13mdl1 ;
   _NAME_ = 'sales';
run;

proc x13 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 ;

proc x13 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 ;