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;
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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.