Hello,
I want to know simple code how to detect and display only outliers
I do not know cutoff values.
Thanks
Best Regards
Agate
This may be simplest to learn extreme values of your data.
Example:
title 'Extreme Blood Pressure Observations';
ods select ExtremeObs;
proc univariate data=BPressure;
var Systolic Diastolic;
id PatientID;
run;
Base SAS(R) 9.2 Procedures Guide: Statistical Procedures, Third Edition
There are an infinite number of methods you could use. Another simple method might be to classify any observation as an outlier if it falls above or below the outer fences of a boxplot:
Lower outer fence: Q1 - 3*IQ
Upper outer fence: Q3 + 3*IQ
Where IQ is the interquartile range, Q1 is the first quartile, and Q3 is the third quartile.
Thanks for your reply.
What would be code for displaying only values above or below the outer fences of a boxplot.
I have tried to create the program but unsuccessfully.
You could try something like this. I'm sure there's more elegant code, but this is what I whipped up in a minute. All you'd need to do is replace the values of dsn with your dataset name and VariableOfInterest with the variable name in the dsn dataset that you want to examine for outliers.
%let VariableOfInterest=height;
%let dsn=sashelp.class;
data work.temp;
set &dsn;
run;
proc univariate data=work.temp noprint;
var &VariableOfInterest;
output out=work.IQRData Q1=Q1 Q3=Q3 QRANGE=IQR;
run;
proc sql noprint;
select Q1-3*IQR, Q3+3*IQR into :lowerfence, :upperfence
from
work.IQRData;
quit;
%put Outliers are those observations less than &lowerfence and greater than &upperfence;
data work.outliers;
set work.temp;
if &VariableOfInterest gt &upperfence or height lt &lowerfence then output;
run;
Thank you very much! That works perfect!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.