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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 1253 views
  • 0 likes
  • 2 in conversation