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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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