Help using Base SAS procedures

The PCTL function in PROC IML

Reply
Super Contributor
Posts: 281

The PCTL function in PROC IML

The IML manual says that the data step function PCTL will work in PROC
IML. Great, except I can make it work in a useful way.

If x is a 10x1 vector, then

median=pctl(50,x);

doesn't really work the way I would hope it works. It gives me a 10x1
vector in return, the median of each value in the original matrix x.
How non-useful!

It does work properly if I write

median=pctl(50,x[1],x[2],x[3],x[4],x[5],x[6],x[7],x[8],x[9],x[10]);

but this isn't a useful way to do things for general problems where x
can be any size.

So, is there a way to have the PCTL function work in a useful way in
PROC IML?
SAS Super FREQ
Posts: 3,473

Re: The PCTL function in PROC IML

You can get the median (50th pctl) and the 25th and 75th percentiles by using the MEDIAN or QUARTILE modules in IMLMLIB:

proc iml;
a = {2 3 2 5 6 8 9 4 12 5}`;
med = median(a);
print med;

q = quartile(a);
print q[rowname={"min" "Q1" "median" "Q3" "max"}];
quit;

For more general percentiles, you can use the SORT call and the RANK function to rank your data.
Ask a Question
Discussion stats
  • 1 reply
  • 494 views
  • 0 likes
  • 2 in conversation