BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
GKati
Pyrite | Level 9

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

3 REPLIES 3
Astounding
PROC Star

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.

 

GKati
Pyrite | Level 9
Perfect! Thx
PeterClemmensen
Tourmaline | Level 20

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

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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