BookmarkSubscribeRSS Feed
Paige
Quartz | Level 8
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?
1 REPLY 1
Rick_SAS
SAS Super FREQ
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.

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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
  • 1 reply
  • 2088 views
  • 0 likes
  • 2 in conversation