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: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 591 views
  • 1 like
  • 3 in conversation