SAS Enterprise Guide

Desktop productivity for business analysts and programmers
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jfcubells
Calcite | Level 5

 Hello!

 

I'm trying to calculate Q1, Q3 and IQR to identify outliers from a dataset. The problem is that I need Q1, Q3 and IQR for each client and each product.

 

When I calculate the Median, I have no problems, but with the other measures it doesn't work the way I expect.

 

proc sql;
create table "Output" as
           select *, median(quantity) as median, PCTL(25,quantity) as Q1, PCTL(75,quantity) as Q3, IQR(quantity) as IQR
                    from work.documentX
group by Client, Product;
quit;

I uploaded an example with an excel sheet.

 

Thanks a lot for you help!

 

Federico.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

What version of SAS do you have? 

AFAIK percentiles/median don't work in SQL until at least SAS 9.4 and I'm not even sure PCTLs work as well.

 

I would strongly suggest comparing results to PROC MEANS/UNIVARIATE at minimum.

 

You can see/use how I've done this here:

 

https://gist.github.com/statgeek/31316a678433a1db8136

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

PROC UNIVARIATE with a BY statement ought to give you the values you want

--
Paige Miller
ballardw
Super User

Or proc means/summary requesting Q1, Q3 and Qrange with CLASS statement, or Proc Tabulate with the same statistics with the group by as class variables.

Reeza
Super User

What version of SAS do you have? 

AFAIK percentiles/median don't work in SQL until at least SAS 9.4 and I'm not even sure PCTLs work as well.

 

I would strongly suggest comparing results to PROC MEANS/UNIVARIATE at minimum.

 

You can see/use how I've done this here:

 

https://gist.github.com/statgeek/31316a678433a1db8136

jfcubells
Calcite | Level 5

Thanks a lot for all the help you all gave me.

 

The final solution was this one:

Proc MEANS Data=work.dataset
n median qrange p25 p75;
var Quantity;
class Client Product;
ods output summary=ranges;
run;

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 34705 views
  • 0 likes
  • 4 in conversation