BookmarkSubscribeRSS Feed
Agate
Calcite | Level 5

Hello,

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

I do not know cutoff values.

Thanks

Best Regards

Agate

5 REPLIES 5
ashwin4reddy_gmail_com
Calcite | Level 5

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

statistician13
Quartz | Level 8

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.

Agate
Calcite | Level 5

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.

statistician13
Quartz | Level 8

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;

Agate
Calcite | Level 5

Thank you very much! That works perfect! Smiley Happy

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 3412 views
  • 0 likes
  • 3 in conversation