BookmarkSubscribeRSS Feed
NURAO
Obsidian | Level 7

Hi,

 

How can I 'print' the data that has been removed the outliers. Specially when it is univariate data.

6 REPLIES 6
ballardw
Super User

You might want to show the code for what you are currently doing and even some example data so we can see some of your outliers. Example data really only would need one variable with outliers.

 

Default output for proc univariate shows the largest and smallest values by default. Do you need more than those?

 

Likely the approach is going to involve either manually writing a where clause for proc print or code to extract some key values to use as limits.

NURAO
Obsidian | Level 7

PROC IML;
RESET NONAME;

 

A={2,2,3,3,3,3,3,3,3,4,4,4,
4,4,5,5,5,6,6,6,7,7,7,8,
8,9,10,14,14,15,20,21,23};
mini=A[><,];
Q=quartile (A);
Q3=Q[4,1];
Q1=Q[2,1];
IQR=Q3-Q1;
L2=Q1-(1.5*IQR);
U2=Q3+(1.5*IQR);
PRINT "L2=" L2,
"U2=" U2;
maxA=max (A);
minA=min (A);
print "mini=" minA,
"max=" maxA;

Here, L2 and U2 are the fences to detect outliers. Based on data A, 20,21 and 23 are the outliers. So my intention is, i want to "print" the data set A by excluded those outliers.

SAS_Rob
SAS Employee

You should just have to use the LOC function to subset the matrix.

 

newa=a[loc(a>l2 & a<u2)]; 

Ksharp
Super User

You really should post it at IML forum, since your code is IML code.

 

PROC IML;
RESET NONAME;
 
A={2,2,3,3,3,3,3,3,3,4,4,4,
4,4,5,5,5,6,6,6,7,7,7,8,
8,9,10,14,14,15,20,21,23};
mini=A[><,];
Q=quartile (A);
Q3=Q[4,1];
Q1=Q[2,1];
IQR=Q3-Q1;
L2=Q1-(1.5*IQR);
U2=Q3+(1.5*IQR);
PRINT "L2=" L2,
"U2=" U2;
maxA=max (A);
minA=min (A);
print "mini=" minA,
"max=" maxA;



left=A[loc(L2<a & a<U2)];
print "exclude outliers: " left;
quit;
NURAO
Obsidian | Level 7

Got it. Thank you

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1561 views
  • 0 likes
  • 4 in conversation