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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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