Using Switch Variables
See SHWSVAR in the SAS/QC Sample Library
As an alternative to reading a LIMITS= data set and using a
WHERE statement, you can provide two special switch variables
named _COMP_ and _DISP_ in the input data set.
The rules for using these variables are as follows:
Switch variables must be character variables of length one.
Valid values for these variables are
Y (or y) and N (or n).
A blank value is treated as Y.
Subgroups for which _COMP_ is equal to Y are included
in computations of parameter estimates and control limits,
and observations for which _COMP_ is equal to N are excluded.
Subgroups for which _DISP_ is equal to Y are displayed
on the chart, and subgroups
for which _DISP_ is equal to N are not displayed.
If the chart statement creates a chart for variables, you can
provide two additional switch variables named _COMP2_ and
_DISP2_, which are defined similarly to _COMP_ and _DISP_.
In this case, the variable
_COMP_ specifies which subgroups are used to estimate the
process mean , and the variable
_COMP2_ specifies which subgroups are used to estimate the
process standard deviation .The variable _DISP_ specifies which subgroups are displayed
on the primary chart ( chart, median chart, or
individual measurements chart), and the
variable _DISP2_ specifies which subgroups are displayed
on the secondary chart (R chart or s chart).
The variables _COMP_ and _COMP2_ are not applicable when
control limits or control limit parameters are read from a
LIMITS= data set.
_DISP_ and _DISP2_ take precedence over the display
controlled by the LIMITN= and ALLN options.
If the input data set is a DATA= data set with multiple observations
switch variable values must be constant
within a subgroup.
Switch variables are saved in OUTHISTORY= and OUTTABLE= data sets.
Subgroups for which _DISP_ is equal to N are not saved
in an OUTTABLE= data set, and such subgroups are not displayed
in tables created
with the TABLE and related options.
The following statements illustrate how the switch variables
_COMP_ and _DISP_ can be used with the bottle production
length _comp_ _disp_ $ 1;
if day = '13JAN94'D then _comp_ = 'n';
else if day = '14JAN94'D then _comp_ = 'n';
else if day <= '31JAN94'D then _comp_ = 'y';
else _comp_ = 'n';
if day <= '31JAN94'D then _disp_ = 'n';
else _disp_ = 'y';
title 'Analysis of February Production';
proc shewhart data=bottles;
pchart ncracks * day / subgroupn = nbottles
label ncracks = 'Proportion With Cracks';
The chart is identical to the chart in Figure 47.35.
In general, switch variables are more versatile than WHERE
statements in applications where subgroups are
simultaneously selected for
computation and display.
Switch variables also provide a permanent record of which subgroups
The WHERE statement does not alter the input data set; it
simply restricts the observations that are read;
consequently, the WHERE statement can be more efficient
than switch variables for processing large data sets.
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.