80 Cody’s Data Cleaning Techniques Using SAS, Second Edition
yielding the following:
Outliers for SBP based on 2 Standard Deviations
Trimming 20% from the Top and Bottom of the Values
Patno=009 SBP=240
Patno=010 SBP=40
Patno=011 SBP=300
Patno=321 SBP=400
Patno=020 SBP=20
Patno=023 SBP=34
Outliers for DBP based on 2 Standard Deviations
Trimming 20% from the Top and Bottom of the Values
Patno=009 DBP=180
Patno=011 DBP=20
Patno=321 DBP=200
Patno=020 DBP=8
Using the TRIM Option of PROC UNIVARIATE and ODS to
Compute Trimmed Statistics
Using the TRIM= PROC UNIVARIATE option, you can compute and print trimmed statistics or,
by using the Output Delivery System (ODS), you can write these statistics to a SAS data set. If
the value of TRIM is an integer (from 0 to half the number of non-missing observations), this
number of values are trimmed from the top and bottom of the data. If the TRIM value is a
proportion between 0 and .5, this proportion of values will be trimmed from the top and bottom of
the data. As an example, the following program will print statistics for Heart Rate (HR) with 5
values trimmed off both ends of the distribution:
Program 2-24 Using the TRIM= Option of PROC UNIVARIATE
title "Trimmed statistics for HR with TRIM=5";
proc Univariate data=clean.patients trim=5;
var HR;
run;
Chapter 2 Checking Values of Numeric Variables 81
Part of the output from Program 2-24 showing the trimmed statistics is shown next:
Trimmed Means
Percent Number Std Error
Trimmed Trimmed Trimmed Trimmed 95% Confidence
in Tail in Tail Mean Mean Limits DF
17.86 5 74.33333 3.593489 66.75173 81.91493 17
Trimmed Means
Percent
Trimmed t for H0:
in Tail Mu0=0.00 Pr > |t|
17.86 20.68556 <.0001
The next program shows how to use an ODS OUTPUT statement to capture the trimmed values
to a SAS data set.
Program 2-25 Using ODS to Capture Trimmed Statistics from PROC UNIVARIATE
ods output TrimmedMeans=Trimmed5(keep=VarName Mean Stdmean DF);
ods listing close;
proc univariate data=clean.patients trim=5;
var HR SBP DBP;
run;
ods output close;
ods listing;
The first ODS statement requests that the trimmed statistics produced by PROC UNIVARIATE
be sent to a data set that you have named TRIMMED5. (Please see the explanation of how to
obtain the names of output objects following Program 2-4.) The other ODS statement closes the
listing file since you do not want to print the values—only to place them in a SAS data set.
Finally, the last two ODS statements close the OUTPUT destination (the SAS data set
TRIMMED5) and reopen the listing file. Do not use the NOPRINT option of PROC
UNIVARIATE to turn off the listing file. If you do so, the ODS OUTPUT statement will not be
able to output anything to your SAS data set.

Get Cody's Data Cleaning Techniques Using SAS, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.