Run Sum Control Chart

 /****************************************************************/
 /*          S A S   S A M P L E   L I B R A R Y                 */
 /*                                                              */
 /*    NAME: SHWRSUM                                             */
 /*   TITLE: Run Sum Control Chart                               */
 /* PRODUCT: QC                                                  */
 /*  SYSTEM: ALL                                                 */
 /*    KEYS: Shewhart Charts, Run Sum Control Charts,            */
 /*   PROCS: SHEWHART                                            */
 /*    DATA:                                                     */
 /*                                                              */
 /*     REF: Reynolds, J. H.(1971). "The Run Sum Control Chart   */
 /*          Procedure,"  Journal of Quality Technology, Vol. 3, */
 /*          pp. 23-27.                                          */
 /*                                                              */
 /*          Roberts, S. W. (1958). "Properties of Control Chart */
 /*          Zone Tests," Bell System Technical Journal, Vol. 37.*/
 /*                                                              */
 /****************************************************************/
options ps=60 ls=80 nodate;

title 'Run Sum Control Chart';

data one;
   drop i;
   retain subgrp;
   input  subgrp @;
   do i=1 to 4;
      input  x @@;
      output;
      end;
   cards;
    1  9.0  9.6 10.2  8.4
    2 10.5  9.5  9.9 10.9
    3 10.7 11.1 11.0 10.8
    4  9.5 10.5 10.3  9.7
    5  9.6 10.2  9.4 10.0
    6 11.8 12.2 12.5 11.5
    7 12.0 12.4 11.8 12.6
    8 11.0 10.8 10.3 11.5
    9 11.0 12.0 11.3 11.7
   10 12.0 11.8 11.3 12.5
   ;

 /**************************************************************/
 /* Invoke PROC SHEWHART and produce OUTTABLE= dataset         */
 /*                                                            */
 /* From previous experience you know that mean=10 and sigma=2 */
 /**************************************************************/

proc shewhart data=one;
   xchart x*subgrp
                  /nochart
                   outtable = table
                   sigma0   = 2
                   mu0      = 10;
   run;

 /* Compute Run Sum Test */

data runsum;
   set table;
   informat _tests_ $8.;
   retain S sign;
   label RunSum = 'Run Sum'
         Score  = 'Score';
   i      = 0;
   sigma  = 2;
   sigmax = 2/sqrt(_subn_);
   if ( _subx_ < _mean_ ) then do;
      do while ( ( _mean_ - (i+1) * sigmax ) > _subx_ );
         i+1;
         end;
      if ((S > 0) & (sign='+')) then S=0;
      sign  = '-';
      end;
   else do;
      do while ( ( _mean_ + (i+1) * sigmax ) < _subx_ );
         i+1;
         end;
      if ((S > 0) & (sign='-')) then S=0;
      sign  = '+';
      end;
   zone    = i;
   S + zone;
   string1 = put(zone,7.);
   string2 = put(S,7.);
   string1 = left(string1);
   string2 = left(string2);
   Score   = sign||string1;
   RunSum  = sign||string2;
   _tests_ = '        ';
   if S > 4 then do;
      _tests_ = '1       ';
      S       = 0;
      end;
   drop i string1 string2 sign zone S sigma;
   run;

 /* Produce Run Sum Control Chart */

symbol1 v=dot h=.75;
proc shewhart table=runsum;
   xchart x*subgrp (RunSum Score) /
                   blocklabtype = scaled
                   blockpos     = 3
                   hoffset      = 4
                   cframe       = gray
                   cinfill      = yellow
                   sigma0       = 2
                   mu0          = 10
                   xsymbol      = mu0
                   tests        = 1
                   testlabel    = 'Alert'
                   novangle;
   run;

goptions reset=all;