Boxplot Example Grouped by Machine

This code is also available in: Deutsch Español Français
Difficulty Level
Beginner
Published on :
This script illustrates the use of the BOXPLOT procedure to visualize quality control data. It first creates an internal dataset containing diameter measurements, sample number, and machine identifier. Then, it generates a graph where diameters are plotted by sample, with visual grouping by machine, allowing comparison of variations between different machines.
Data Analysis

Type : CREATION_INTERNE


Data is generated directly in the code via a DATA step and the DATALINES statement.

1 Code Block
DATA STEP Data
Explanation :
Creation of the SAS table 'Parts'. Use of a 'do i=1 to 4' loop to read four diameter measurements ('Diam') per raw data line for each combination of sample ('Sample') and machine ('Machine').
Copied!
1DATA Parts;
2 LENGTH Machine $ 4;
3 INPUT Sample Machine $ @;
4 DO i= 1 to 4;
5 INPUT Diam @;
6 OUTPUT;
7 END;
8 drop i;
9 DATALINES;
10 1 A386 4.32 4.55 4.16 4.44
11 2 A386 4.49 4.30 4.52 4.61
12 3 A386 4.44 4.32 4.25 4.50
13 4 A386 4.55 4.15 4.42 4.49
14 5 A386 4.21 4.30 4.29 4.63
15 6 A386 4.56 4.61 4.29 4.56
16 7 A386 4.63 4.30 4.41 4.58
17 8 A386 4.38 4.65 4.43 4.44
18 9 A386 4.12 4.49 4.30 4.36
1910 A455 4.45 4.56 4.38 4.51
2011 A455 4.62 4.67 4.70 4.58
2112 A455 4.33 4.23 4.34 4.58
2213 A455 4.29 4.38 4.28 4.41
2314 A455 4.15 4.35 4.28 4.23
2415 A455 4.21 4.30 4.32 4.38
2516 C334 4.16 4.28 4.31 4.59
2617 C334 4.14 4.18 4.08 4.21
2718 C334 4.51 4.20 4.28 4.19
2819 C334 4.10 4.33 4.37 4.47
2920 C334 3.99 4.09 4.47 4.25
3021 C334 4.24 4.54 4.43 4.38
3122 C334 4.23 4.48 4.31 4.57
3223 C334 4.27 4.40 4.32 4.56
3324 C334 4.70 4.65 4.49 4.38
34;
2 Code Block
PROC BOXPLOT
Explanation :
Activation of ODS (Output Delivery System) graphics for modern rendering. Execution of the BOXPLOT procedure on the 'Parts' table. The 'plot' statement creates box plots of the 'Diam' variable for each 'Sample'. The '(Machine)' syntax specifies that the data should be grouped (stratified) by the 'Machine' variable.
Copied!
1ods graphics on;
2title 'Box Plot for Diameter Grouped By Machine';
3PROC BOXPLOT DATA=Parts;
4 plot Diam*Sample (Machine) / odstitle = title;
5 label Sample = 'Sample Number'
6 Machine = 'Machine'
7 Diam = 'Diameter';
8RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : SAS SAMPLE LIBRARY


Related Documentation

Aucune documentation spécifique pour cette catégorie.