DATA Step, Macro, Functions and more

Calculate averages by percentiles

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 107
Accepted Solution

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.

 

View solution in original post


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

Re: Calculate averages by percentiles

Posted in reply to Astounding
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 Smiley Happy

 

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

 

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 146 views
  • 0 likes
  • 3 in conversation