PROC IML;
scores={90,62,66,68,70,72,73,74,78,78,78,79,80,81,82,
82,82,84,84,85,85,85,85,87,88,89,89,89,89,61};
PRINT scores;
quartiles=QUARTILE(scores);
PRINT quartiles;
/** Start Percentile **/
START percentile(x,pct);
CALL SORT(x,1);
count=NROW(x);
pct=pct/100*(count+1);
fpct=FLOOR(pct);
cpct=CEIL(pct);
IF fpct=cpct THEN percentile=x[pct];
ELSE percentile=x[fpct]+(pct-fpct)* (x[cpct]-x[fpct]);
/* SAS PCTLDF */
RETURN(percentile);
FINISH;
percentile=PERCENTILE(scores,25);
/** End Percentile **/
CALL SORT(scores,1); /* sorts the scores in ascending order */
count=NROW(scores);
quantile=scores[CEIL(count*.25)];
PRINT quartiles, "25th Percentile:"
percentile, "25th Quantile:" quantile;
QUIT;
|