02-07-2012 10:10 PM
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.
02-07-2012 10:39 PM
My assumption Q1 and Q3 - Interquartile Range
Firstly, get the median of the variable:
select median(x) as M from tbl_nm;
Ex: M = 7500
Now that you have got your median you can find Q1 which is 25th Quantile.
select median(x) as Q1 where x <= 7500;
Next, go for Q3 which is 75th Quantile:
select median(x) as Q3 where x >= 7500
Is this what you are looking for?
02-08-2012 09:40 PM
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 ;
proc sql ;
select median(age) from sashelp.class ;
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.