BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Santt0sh
Lapis Lazuli | Level 10

Hi All,

 

I m trying to capture the count of the Outliers. I have used the below code.

 

 

DATA   A;
INPUT A B C;
DATALINES;
1 2 3
1 2 3
45 45 66
34 556 334
;

PROC UNIVARIATE DATA=A OUTTABLE=A1;
VAR A;
RUN;

 

DATA A2;
SET A1;
UPPER=_Q1_ *(1.5 + _QRANGE_);
LOWER=_Q3_ *(1.5 - _QRANGE_);
CALL SYMPUT('UPPER', UPPER);
CALL SYMPUT('LOWER', LOWER);
RUN;

%PUT &UPPER. &LOWER.;

 

DATA X;
U="&UPPER.";
L="&LOWER.";
RUN;

 

DATA X;
SET A;
WHERE A GE &UPPER. OR A LE &LOWER.;
RUN;

 

DATA X1;
SET A;
WHERE A GE &UPPER. ;
RUN;

 

DATA X2;
SET A;
WHERE A LE &LOWER.;
RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
4 REPLIES 4
PGStats
Opal | Level 21

Here is an example of robust outlier detection in biological data (sampled fish measurements):

 

/* Calculate a body mass index (BMI) for each sampled fish */
data have;
set sashelp.fish;
BMI= weight / length1**3;
run;

/* identify the BMI outliers (fish that are too thin or too fat) */
proc robustreg data=have;
where species in  ("Perch" "Roach");
by species notsorted;
model BMI = / diagnostics(all);
output out=want outlier=outlier residual=residual;
run;

/* Report on the number of outliers for each species */
proc sql;
select * 
from want
where outlier;
select 
    species, 
    sum(outlier) as count
from want
group by species;
quit;

PGStats_0-1647398318117.png

 

PG
Santt0sh
Lapis Lazuli | Level 10
Hi,

Thanks let me try this!

Regards
Santt0sh
Lapis Lazuli | Level 10
Thank you for the suggestion!!
It worked
PaigeMiller
Diamond | Level 26

@Santt0sh 

Please mark the reply from @PGStats as the correct answer, and unmark your own reply as the answer.

--
Paige Miller

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 4 replies
  • 505 views
  • 1 like
  • 3 in conversation