Autocorrelated Process Data Trend Chart

 /****************************************************************/
 /*          S A S   S A M P L E   L I B R A R Y                 */
 /*                                                              */
 /*    NAME: SHWARIMA                                            */
 /*   TITLE: Autocorrelated Process Data Trend Chart             */
 /* PRODUCT: QC                                                  */
 /*  SYSTEM: ALL                                                 */
 /*    KEYS: Shewhart Charts, Trend Charts,                      */
 /*   PROCS: SHEWHART ARIMA                                      */
 /*    DATA:                                                     */
 /*                                                              */
 /*     REF: SAS/QC Software:  Examples                          */
 /*    MISC:                                                     */
 /*                                                              */
 /****************************************************************/
options ps=60 ls=80;

data process;
   e1 = 0;
   do t = 1 to 111;
      e = 7.0 * rannor(33333);
      y = t + e - .7*e1;
      e1 = e;
      if t > 100 then y = .;
      if t > 0   then output;
      end;
run;

 /* Fit ARIMA Model */
proc arima data = process;
   identify var = y crosscorr = t;
   estimate q = 1 input = t method = ml;
   forecast lead = 10 out = arima;
run;

 /* Data for Trend Chart Example */
data forecast;
   keep t yx forecast ys yn l95 u95;
   set arima;
   yx=y;
   yn=5;
   ys=11;
   t=_N_;
run;

data model;
   length text $ 32 function color style $ 8 position $ 1;
   when     = 'A';
   xsys     = '2';
   ysys     = '2';
   position = 'C';
   function = 'label';
   X        = 1.0;
   Y        = 100.0;
   color    = 'white';
   style    = 'none';
   text     = 'Y(t) - Y(t-1) = (1 - .61 B) e(t)';
   size     = 1;
   output;
   run;

data arima; set arima; t = _N_ ; run;
data arima2;
   set arima;
   if t<101 then delete;
run;

data predict;
   length  function color $ 8 ;
   when  = 'A';
   xsys  = '2';
   ysys  = '2';
   line  = 2;
   color = 'white';
   set arima2;
   x     = t;
   y     = forecast;
   if t=101 then function='MOVE';
   else          function='DRAW';

data l95;
   length function color $ 8 ;
   when  = 'A';
   xsys  = '2';
   ysys  = '2';
   line  = 1;
   color = 'yellow';
   set arima2;
   x     = t;
   y     = L95;
   if t=101 then function='MOVE';
   else          function='DRAW';

data u95;
   length function color $ 8 ;
   when  = 'A';
   xsys  = '2';
   ysys  = '2';
   line  = 1;
   color = 'yellow';
   set arima2;
   x     = t;
   y     = U95;
   if t=101 then function='MOVE';
   else          function='DRAW';
run;
data anno2;
   set model predict l95 u95;
run;

 /* Create Trend Chart */
title 'Trend Chart With ARIMA(0,1,1) Model';
proc shewhart history=forecast;
   xchart y*t /
      cframe   = blue
      cinfill  = green
      ypct1    = 40
      trendvar = forecast
      npanel   = 115
      stddevs
      anno2    = anno2
      nolegend
      cconnect = white
      split    = '/'
      novangle;
   label yx='Residual Temp/Fitted Temp'
         t ='Hour (t)';
   run;

goptions reset=all;