turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- SAS program to detect and display only outliers

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-29-2013 01:40 PM

Hello,

I want to know simple code how to detect and display only outliers

I do not know cutoff values.

Thanks

Best Regards

Agate

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-29-2013 04:27 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-29-2013 06:00 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-02-2013 01:59 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-02-2013 02:18 PM

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-03-2013 04:09 AM

Thank you very much! That works perfect!