Published on :
Statistical CREATION_INTERNE

Example 3 Details for PROC BOXPLOT

This code is also available in: Deutsch Español Français
Awaiting validation
This SAS© script creates a dataset simulating copper tube diameters by batch. It then generates box plots to visualize the distribution. The example focuses on the 'clipfactor' option, which allows truncation of the y-axis to prevent extreme values from visually overwhelming the rest of the chart, while signaling these truncations through custom legends.
Data Analysis

Type : CREATION_INTERNE


'Newtubes' data created via DATALINES with nested loops to generate batch identifiers (Batch).

1 Code Block
DATA STEP Data
Explanation :
Dataset creation with continuous reading (@code_sas_json/8_SAS_Intro_ReadFile_MultiCol_@@.json) of diameter values. Nested DO loops generate the 'Batch' group variable (15 batches) with 5 observations per batch.
Copied!
1DATA Newtubes;
2 label Diameter='Diameter in mm';
3 DO Batch = 1 to 15;
4 DO i = 1 to 5;
5 INPUT Diameter @code_sas_json/8_SAS_Intro_ReadFile_MultiCol_@@.json;
6 OUTPUT;
7 END;
8 END;
9 DATALINES;
1069.13 69.83 70.76 69.13 70.81
1185.06 82.82 84.79 84.89 86.53
1267.67 70.37 68.80 70.65 68.20
1371.71 70.46 71.43 69.53 69.28
1471.04 71.04 70.29 70.51 71.29
1569.01 68.87 69.87 70.05 69.85
1650.72 50.49 49.78 50.49 49.69
1769.28 71.80 69.80 70.99 70.50
1870.76 69.19 70.51 70.59 70.40
1970.16 70.07 71.52 70.72 70.31
2068.67 70.54 69.50 69.79 70.76
2168.78 68.55 69.72 69.62 71.53
2270.61 70.75 70.90 71.01 71.53
2374.62 56.95 72.29 82.41 57.64
2470.54 69.82 70.71 71.05 69.24
25;
2 Code Block
PROC BOXPLOT
Explanation :
Generation of a standard box plot with ODS Graphics enabled. Displays the diameter distribution for each batch.
Copied!
1ods graphics on;
2title 'Box Plot for New Copper Tubes' ;
3PROC BOXPLOT DATA=Newtubes;
4 plot Diameter*Batch / odstitle = title;
5RUN;
3 Code Block
PROC BOXPLOT
Explanation :
Generation of the plot with the 'clipfactor=1.5' option. This option truncates boxes whose whiskers would extend too far (extreme values), allowing zooming in on the central distribution.
Copied!
1title 'Box Plot for New Copper Tubes' ;
2PROC BOXPLOT DATA=Newtubes;
3 plot Diameter*Batch /
4 odstitle = title
5 clipfactor = 1.5;
6RUN;
4 Code Block
PROC BOXPLOT
Explanation :
Enhanced version of the truncated chart. The 'cliplegend' option adds an explanatory legend and 'clipsubchar' defines the '#' character to mark batches that have been truncated.
Copied!
1title 'Box Plot for New Copper Tubes' ;
2PROC BOXPLOT DATA=Newtubes;
3 plot Diameter*Batch /
4 odstitle = title
5 clipfactor = 1.5
6 cliplegend = '# Clipped Boxes'
7 clipsubchar = '#';
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