DATA Step, Macro, Functions and more

Tip: How to compute percentiles (quantiles)

Accepted Solution Solved
Reply
Contributor
Posts: 65
Accepted Solution

Tip: How to compute percentiles (quantiles)

I have a set of data. I want to compute the percentiles of each data point in the whole data set. for example, what is the percentile of data point 11326.21369 in the data set? The below is part of my data.

  Cost

11326.210369
12486.48938
12461.600695
17078.181683
20830.827535
21301.654723
19246.458983
17233.110851
20086.991101
18998.225999
18755.580299
18363.870699
18084.353599
22674.720499
16680.130049
15838.031999
19773.713649
16864.323849
17499.784599
16918.186999
18383.525249
20307.965549
18135.335899
16504.779198
22346.398306
18484.330644
18335.447644
19685.665094
19591.907594
18702.066744
18938.583444
17878.801744
23398.002544
18101.282344
18554.513094
18812.566344
21834.429194
19587.505132
16619.15172


Accepted Solutions
Solution
‎01-27-2017 02:57 PM
PROC Star
Posts: 7,363

Re: Tip: How to compute percentiles (quantiles)

[ Edited ]

Easiest might be to use PROC RANK. e.g.:

 

proc rank data=have out=want  groups=100;
  var cost;
  ranks cost_rank;
run;

If you want quantiles just change the groups=100 option to groups=5.

 

HTH,

Art, CEO, AnalystFinder.com

 

View solution in original post


All Replies
Solution
‎01-27-2017 02:57 PM
PROC Star
Posts: 7,363

Re: Tip: How to compute percentiles (quantiles)

[ Edited ]

Easiest might be to use PROC RANK. e.g.:

 

proc rank data=have out=want  groups=100;
  var cost;
  ranks cost_rank;
run;

If you want quantiles just change the groups=100 option to groups=5.

 

HTH,

Art, CEO, AnalystFinder.com

 

SAS Super FREQ
Posts: 3,482

Re: Tip: How to compute percentiles (quantiles)

[ Edited ]

If you want to assign each value an integer (the percentile) between 0 and 99, you can use PROC RANK with GROUPS=100.

 

proc rank data=a groups=100 out=Pctls;
var x;
ranks pctl;
run;

 

The PCTLS data set contains the original variable and the corresponding percentiles.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 175 views
  • 0 likes
  • 3 in conversation