## Calculate averages by percentiles

Solved
Frequent Contributor
Posts: 107

# Calculate averages by percentiles

Hi All,

I would like to calculate the average of costs at each percentile based on contracts. I got as far as calculating the percentile limits, but this gives me a dataset with varilables; P_1, P-2, ... P_100. I need to somehow merge these into my original dataset and then use proc means I guess to calculate the averege cost per percentile.

What's the most efficient way of doing this?

data claims;

input client year cost contract;

datalines;

18 2011 589.92 10.2

19 2010 1629.8 11.5

20 2011 1813.29 2.3

21 2012 412.06 3.2

22 2012 219.82 0.4

23 2010 3669.98 5.9

24 2012 4879.63 6.8

;

run;

proc univariate data=claims noprint;

var contract;

output pctlpre=P_ pctlpts= 1 to 100;

run;

Accepted Solutions
Solution
‎02-17-2018 04:10 PM
Super User
Posts: 6,754

## Re: Calculate averages by percentiles

It can be done, but this is the hard way.

Instead, use PROC RANK to create an output data set with percentile assigned.  You won't have the cutoffs, but you won't need them either.

All Replies
Solution
‎02-17-2018 04:10 PM
Super User
Posts: 6,754

## Re: Calculate averages by percentiles

It can be done, but this is the hard way.

Instead, use PROC RANK to create an output data set with percentile assigned.  You won't have the cutoffs, but you won't need them either.

Frequent Contributor
Posts: 107

Perfect! Thx
PROC Star
Posts: 1,269

## Re: Calculate averages by percentiles

Use PROC STDIZE to get results in long format and merge accordingly as in the article below

https://blogs.sas.com/content/iml/2013/10/23/percentiles-in-a-tabular-format.html

☑ This topic is solved.