FOCUS AREAS

SAS/ETS Examples

Overlaying Multiple Forecast Methods in Time Series Plots


Contents | Back to Example

SAS Program

   /*-----------------------------------------------------------------
     Example: Overlaying Mutiple Forecast Methods in Time Series Plots
     Requires: SAS/ETS, SAS/STAT, SAS/GRAPH
     Version: 9.0
     ------------------------------------------------------------------*/



goptions reset=all;

/* -------  Read Initial Data  ------- */

data leadprd;
   input date:monyy5. leadprod @@;
   format date monyy5.;
   title 'Lead Production Data';
   title2 '(in tons)';
   datalines;
jan90 38500 feb90 37900 mar90 36900 apr90 38600
may90 36400 jun90 33300 jul90 34000 aug90 38000
sep90 37400 oct90 42300 nov90 36900 dec90 34800
jan91 33900 feb91 34000 mar91 37200 apr91 33300
may91 29800 jun91 24700 jul91 30800 aug91 31100
sep91 32400 oct91 32900 nov91 29100 dec91 31800
jan92 32100 feb92 30500 mar92 36800 apr92 30300
may92 29500 jun92 24700 jul92 27600 aug92 23800
sep92 21400
;
run;



/* -------  Forecasting Methods  ------- */

   /* -- Using PROC FORECAST -- */

   proc forecast data=leadprd out=leadout1 out1step
      lead=12 interval=month;
      id date;
      var leadprod;
   run;



   /* -- Using PROC ARIMA -- */

   proc arima data=leadprd;
      i var=leadprod nlag=15;
      e p=1;
      f lead=12 interval=month id=date out=leadout2;
   run;
   quit;



   /* -- Using PROC REG (Time Trend Regression) -- */

   data ttrend;
      set leadout2;
      t+1;
   run;



   proc reg data=ttrend;
      model leadprod = t;
      output out=leadout3 p=ptrend;
   run;
   quit;



   /* -------  Data Management  ------- */

   data final;
      set leadout1(keep=date leadprod
                   rename=(leadprod=pfore));
      set leadout2(keep=date leadprod forecast
                   rename=(leadprod=actual forecast=parima));
      set leadout3(keep=date ptrend);
   run;



   /* -------  Graphics Output  ------- */

   goptions cback=white ctitle=bl ctext=bl border
            ftitle=centx ftext=centx;

   title 'Lead Production Data';
   title2 'Plot of Forecast for Lead Production';
   symbol1 i=spline width=1 v=dot  c=black;  /* for actual */
   symbol2 i=spline width=2 v=none c=red;    /* for pfore forecast */
   symbol3 i=spline width=2 v=none c=green;  /* for parima forecast */
   symbol4 i=spline width=2 v=none c=blue;   /* for ptrend forecast */

   axis1 offset=(1 cm)
         label=('Year') minor=none
         order=('01jan90'd to '01jan94'd by year);
   axis2 label=(angle=90 'Lead Production')
         order=(20000 to 45000 by 5000);

   legend1 across=1
           cborder=black
           position=(top inside right)
           offset=(-2,0)
           value=(tick=1 'ACTUAL'
                  tick=2 'PROC FORECAST'
                  tick=3 'PROC ARIMA'
                  tick=4 'TIME TREND')
           shape=symbol(2,.25)
           mode=share
           label=none;



   proc gplot data=final;
      format date year4.;
      plot actual * date = 1
           pfore  * date = 2
           parima * date = 3
           ptrend * date = 4 / overlay noframe
                               href='01sep92'd
                               chref=red
                               vaxis=axis2
                               vminor=1
                               haxis=axis1
                               legend=legend1;
   run;
   quit;