Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find out median in Proc Sql statement

Status
Not open for further replies.

bris1f

Technical User
Apr 29, 2003
1
US
Can you tell me how to find out medican in the proc sql statement? I don't want to use proc means because I need to find the median of different groups which are seperated by character values. Thank youj.
 
I normally use the proc sql code to create a table. Then
I would use code like the following:
proc sql;
create table test as
select ........code
from .....code
where .....;

data temp;set test;
proc sort;by yourcharvariable;
PROC MEANS MEDIAN MEAN STD MIN MAX SUM MAXDEC=2 noprint;BY yourcharvariable;
VAR a b ;

output out = work.rep
Median= medA medb
mean = XA XB
min = MINA MINB
max = MAXA MAXB
sum= SUMA SUMB ;
RUN;


work.rep would then be used for any output that you may want to do...


This approach may not be desirable if you have very large file sizes but works ok for my work.

 
In principle you can calculate a lot of different things during a proc sql. But you can't calculate a median because this function is not available. :-(

For a means calculation you would use something like this:

proc sql;
create table summary as
select col1,
col2,
col3
mean(var1) as newcol
from oldtable
group by col1, col2, col3;
quit;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top