SPC Procedure
Getting Started: SPC Procedure
(View the complete code for this example.)
A brewery monitors its bottling process to ensure that each bottle is filled with the proper amount of beer. The following statements create a SAS data set named Beer that contains the amount of beer, recorded in fluid ounces, for 23 sample batches:
data Beer;
input Batch size @;
do i=1 to size;
input Amount @@;
output;
end;
drop i size;
label Batch ='Batch Number';
datalines;
1 5 12.01 11.97 11.93 11.98 12.00
2 5 11.88 11.98 11.93 12.03 11.92
3 5 11.93 11.99 12.00 12.03 11.95
4 5 11.98 11.94 12.02 11.90 11.97
5 5 12.02 12.02 11.98 12.04 11.90
6 4 11.98 11.98 12.00 11.93
7 5 11.93 11.95 12.02 11.91 12.03
8 5 12.00 11.98 12.02 11.89 12.01
9 5 11.98 11.93 11.99 12.02 11.91
10 5 11.97 12.02 12.05 12.01 11.97
11 5 12.02 12.01 11.97 12.02 11.94
12 5 11.93 11.83 11.99 12.02 12.01
13 5 12.01 11.98 11.94 12.04 12.01
14 5 11.98 11.96 12.02 12.00 12.00
15 5 11.97 11.99 12.03 11.95 11.96
16 5 11.99 11.95 11.96 12.03 12.01
17 4 11.99 11.97 12.03 12.01
18 5 11.94 11.96 11.98 12.03 11.97
19 5 11.97 11.87 11.90 12.01 11.95
20 5 11.96 11.94 11.96 11.98 12.05
21 3 12.06 12.07 11.98
22 5 12.01 11.98 11.96 11.97 12.00
23 5 12.00 12.02 12.03 11.99 11.96
;
The format of the Beer data set makes it suitable for analysis by PROC SHEWHART. The process variable is Amount, and the subgroup variable is Batch. Figure 2 shows a partial listing of the data set.
Figure 2: Data Set Beer (PROC SHEWHART Format)
| Batch | Amount |
|---|---|
| 1 | 12.01 |
| 1 | 11.97 |
| 1 | 11.93 |
| 1 | 11.98 |
| 1 | 12.00 |
| 2 | 11.88 |
| 2 | 11.98 |
| 2 | 11.93 |
| 2 | 12.03 |
| 2 | 11.92 |
| 3 | 11.93 |
| 3 | 11.99 |
| 3 | 12.00 |
| 3 | 12.03 |
| 3 | 11.95 |
The following DATA step modifies Beer so that it is suitable for analysis by PROC SPC:
data Beer;
length processname $16 subgroupname $8;
processname='Amount';
subgroupname='Batch';
set Beer(rename=(Amount=process Batch=subgroup));
run;
The modified data set is shown in Figure 3.
Figure 3: Data Set Beer (PROC SPC Format)
| processname | subgroupname | subgroup | process |
|---|---|---|---|
| Amount | Batch | 1 | 12.01 |
| Amount | Batch | 1 | 11.97 |
| Amount | Batch | 1 | 11.93 |
| Amount | Batch | 1 | 11.98 |
| Amount | Batch | 1 | 12.00 |
| Amount | Batch | 2 | 11.88 |
| Amount | Batch | 2 | 11.98 |
| Amount | Batch | 2 | 11.93 |
| Amount | Batch | 2 | 12.03 |
| Amount | Batch | 2 | 11.92 |
| Amount | Batch | 3 | 11.93 |
| Amount | Batch | 3 | 11.99 |
| Amount | Batch | 3 | 12.00 |
| Amount | Batch | 3 | 12.03 |
| Amount | Batch | 3 | 11.95 |
The PROC SPC data format is more conducive than the PROC SHEWHART format to analyzing many processes at once. Because process names are recorded in the process name variable, you do not have to list the processes to be analyzed in the procedure syntax.
The following statements create a data table called mylib.AllProcesses that contains the beer bottle data along with data from seven other SAS data sets (not shown here) that appear in the SHEWHART procedure chapter of SAS/QC User's Guide. These statements assume that your libref is named mylib, but you can substitute any appropriately defined libref.
data mylib.AllProcesses;
set Beer Detergent Disks Partgaps Times Turbine Wafers Wire;
format subgroup;
run;
Note: Input data must be in a table that is accessible in your session. You can refer to this table by using a two-level name. The first level is a libref, and the second level is the table name. For more information, see the section Using SAS Viya Workbench in Chapter 2, Shared Concepts.
The following statements use PROC SPC to perform a means and ranges chart analysis of the eight processes.
proc spc data=mylib.AllProcesses;
xrchart;
run;
The XRCHART statement performs an and R chart analysis on the process data, calculating control charts for subgroup means and subgroup ranges. By default, control limits are calculated from the data. Figure 4 shows the resulting output.
Figure 4: PROC SPC Output
| Means and Ranges Chart Summary for ALLPROCESSES | ||||||
|---|---|---|---|---|---|---|
| processname | subgroupname | Number of Subgroups | Means | Ranges | ||
| Number > UCL | Number < LCL | Number > UCL | Number < LCL | |||
| Amount | Batch | 23 | 0 | 0 | 0 | 0 |
| Breakstrength | Sample | 25 | 0 | 0 | 0 | 0 |
| Delay | Day | 11 | 3 | 1 | 2 | 2 |
| Diameter | Batch | 45 | 0 | 1 | 0 | 0 |
| KWatts | Day | 40 | 0 | 0 | 0 | 0 |
| Partgap | Sample | 41 | 0 | 0 | 0 | 0 |
| Time | Lot | 25 | 0 | 0 | 0 | 0 |
| Weight | Lot | 28 | 0 | 0 | 0 | 0 |
The default output from PROC SPC is an exception summary table. For each process, the table shows the number of subgroups that were analyzed and the number of subgroup summary statistics that fell outside the control limits of each chart.
The table in Figure 4 shows signals of unusual variation in process Delay (from the Times data set) and process Diameter (from the Wafers data set). When unusual variation is signaled in a process, you should investigate to find and correct any special causes of variation.