BookmarkSubscribeRSS Feed
Hoz
Calcite | Level 5 Hoz
Calcite | Level 5

I'd like to use median function in proc sq.

It was OK when i wrote down "proc sql; --- select median(x) ----".

But it was NG when "proc sql; --- select q3(x) ---".

I want to know to get Q1,Q3 in proc sql.

Thank you,

Hide

3 REPLIES 3
Pritish
Quartz | Level 8

My assumption Q1 and Q3 - Interquartile Range

Firstly, get the median of the variable:

proc sql;

select median(x) as M from tbl_nm;

quit;

Ex: M = 7500

Now that you have got your median you can find Q1 which is 25th Quantile.

proc sql;

select median(x) as Q1 where x <= 7500;

quit;

Next, go for Q3 which is 75th Quantile:

proc sql;

select median(x) as Q3 where x >= 7500

quit;

Is this what you are looking for?

Hoz
Calcite | Level 5 Hoz
Calcite | Level 5

I see.  It was the way to calculate Q1, Q3 with median function.

Thank you for your quick response, zinzuwadia.

Best regards,

Hide

Howles
Quartz | Level 8

Look at your results more carefully and you will see that PROC SQL does not support MEDIAN as a summary statistic. You can use the SAS MEDIAN function in PROC SQL, but with one argument all you get is the trivial result that the median of a single number is that number.

proc means median data=sashelp.class ;

var age ;

run ;

proc sql ;

select median(age) from sashelp.class ;

quit ;

Celko's SQL median has been implemented in SAS (http://www.sascommunity.org/wiki/Celko's_Median). That should get you started if you really have to do this in SQL.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 22247 views
  • 0 likes
  • 3 in conversation