Programming the statistical procedures from SAS

How to 'print' the remaining data after remove the outliers?

Reply
New Contributor
Posts: 4

How to 'print' the remaining data after remove the outliers?

Hi,

 

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

Super User
Posts: 10,516

Re: How to 'print' the remaining data after remove the outliers?

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.

New Contributor
Posts: 4

Re: How to 'print' the remaining data after remove the outliers?

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 Employee
Posts: 15

Re: How to 'print' the remaining data after remove the outliers?

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

 

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

New Contributor
Posts: 4

Re: How to 'print' the remaining data after remove the outliers?

Thank you

Super User
Posts: 9,682

Re: How to 'print' the remaining data after remove the outliers?

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;
New Contributor
Posts: 4

Re: How to 'print' the remaining data after remove the outliers?

Got it. Thank you

Ask a Question
Discussion stats
  • 6 replies
  • 90 views
  • 0 likes
  • 4 in conversation