How to get the median and other quantiles of data in the same row of several vectors using IML functions?
Look at the QNTL subroutine. The QNTL function operates on columns of a matrix, so if you have several vectors you can concatenate them together (use the || operator) and compute all the quantiles at once.
How to do it using SAS 9.2IML? Thanks!
You could adapt my code here which uses the SAS pctl function:
http://listserv.uga.edu/cgi-bin/wa?A2=ind0812A&L=sas-l&D=0&P=35674
But this is not a workable solution unless your matrices will always be small. As Dale said in the same thread:
http://listserv.uga.edu/cgi-bin/wa?A2=ind0812A&L=sas-l&D=0&P=37690
you will probably be better off building your own percentile function.
proc iml;
start myQntl(q, x, p); /* definition 5 from UNIVARIATE doc */
y = colvec(x);
call sort(y,1);
n = nrow(y); /* assume nonmissing data */
q = j(ncol(p),1);
do i = 1 to ncol(p);
j = (n+1)*p; /* position in ordered data */
j1 = floor(j); j2 = ceil(j);/* indices into ordered data */
print j j1 j2;
if j1=j2 then /* return a datum */
q = y[j1];
else /* interpolate between data */
q = (y[j2]+y[j1])/2;
end;
finish;
/* test it */
x = ranuni(j(100,1));
p = {0.1 0.25 0.5 0.75 0.9};
call MyQntl(q, x, p);
print q;
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.
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.