Hello
I know how to calculate percentiles of specific variable.
for exampe:
proc univariate data =sashelp.cars noprint;
var invoice;
output out=outdata PCTLPTS = 5 to 100 by 5 PCTLPRE = P;
run;
My question;
Let's say that I want to know what percentile is value 50000.
How can I answer it via sas code please?
proc rank data=sashelp.cars out=cars_ranks percent;
var invoice;
ranks invoice_r;
run;
proc sort data=cars_ranks;
by invoice;
run;
data want;
set cars_ranks;
prev_invoice=lag(invoice);
if prev_invoice<50000 and invoice>=50000 then output;
keep invoice invoice_r;
run;
So 50000 is percentile 91.589 (rounded-off to 3 decimal places).
In addition to the proc rank approach, there is a straightforward data step approach:
data _null_;
set sashelp.cars (keep=invoice) end=end_of_data;
array freqs {-1:1} _temporary_ (3*0);
freqs{sign(invoice-50000)}+1;
if end_of_data;
pctile_50000 = freqs{-1} / sum(of freqs{*});
put pctile_50000=percent10.4;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.