The OP has complained that the original program I posted did not handle the degenerate case of a sample that has only one observation. Here is the modification that handles N=1:
data q;
input x;
cards;
19967.95
19271.69
16525.2
6885.5
3442.75
;
proc iml;
/* Define function that returns the TYPE=7 sample quantiles. For more info, see https://blogs.sas.com/content/iml/2017/05/24/definitions-sample-quantiles.html*/
start GetRQuantiles(y, probs);
x = colvec(y);
call sort(x);
N = nrow(x); /* assume all values are nonmissing */
p = colvec(probs);
m = 1-p;
j = floor(N*p + m);
g = N*p + m - j;
q = j(nrow(p), 1, x[N]); /* if p=1, x[N]=return max(x) */
if N=1 then return q;
idx = loc(p < 1);
if ncol(idx) >0 then do;
j = j[idx]; g = g[idx];
q[idx] = (1-g)#x[j] + g#x[j+1];
end;
return q;
finish;
/* TEST the function on an example */
use q; read all var "x"; close; /* read sample into x */
p = {12.5, 25, 37.5, 50, 62.5, 75, 87.5, 100} / 100; /* define probabilities */
q = GetRQuantiles(x, p); /* get type=7 sample quantiles */
print p q;
/* for a degenerate sample (N=1), all estimates are equal to x[1] */
q = GetRQuantiles(123.45, p);
print p q;
... View more