Showing results for

- Home
- /
- Programming
- /
- SAS Procedures
- /
- weighted percentiles

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 08-25-2016 02:15 PM
(4442 views)

Hello All, I am wondering whether it is possible to calculate weighted percentiles using proc means.

When I use this syntax, it seems only mean is weighed.

**proc** **means** data= sodiumdata2009 min max mean median p10 q1 q3 noprint;

by Level_1;

var sodp100g;

weight RKVol;

**run**;

Any suggestions?

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

The percentiles are affected as far as I can tell.

Perhaps your data isn't affected by the weights for some reason?

If the weights are small?

```
data check;
set sashelp.class;
x=floor(rand('uniform')*8)+1;
run;
proc means data=check n p5 p10 p90 p95;
title 'no weights';
var weight;
run;
proc means data=check n p5 p10 p90 p95;
title 'weights';
var weight;
weight x;
run;
```

14 REPLIES 14

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

The percentiles are affected as far as I can tell.

Perhaps your data isn't affected by the weights for some reason?

If the weights are small?

```
data check;
set sashelp.class;
x=floor(rand('uniform')*8)+1;
run;
proc means data=check n p5 p10 p90 p95;
title 'no weights';
var weight;
run;
proc means data=check n p5 p10 p90 p95;
title 'weights';
var weight;
weight x;
run;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi Reeza,

When I ran your code I saw the difference in only one value, so I went back to my data and did more checking. Same as in your example I now see the difference in a very few values, so I guess the weighting is working. I kind of expected to see all weighted values to be different from unweighted one. Problem solved! Thank you All for contribution!

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

By any chance is your RKVol variable a COUNT type variable? If so then you may want to use FREQ instead of Weight.

That will in effect replicate each value of your variable RKVol times.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

It is not an integer

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

So how about:

proc univariate data=sodiumdata2009 noprint;

by Level_1

var sodp100g;

weight RKVol;

output out=want min=min max=max mean=mean p10=p10 q1=q1 q3=q3;

run;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I have the same looking code:

**proc** **means** data=data2009.sodiumdata2009 min max mean median p10 q1 q3 noprint;

by Level_1;

var sodp100g;

weight RKVol;

output out=Weighted_2009data mean=mean_per100gr_sodium_mg2009 min=Min_per100gr_sodium_mg2009 median=median_per100gr_sodium_mg2009 p10=_10th_2009 q1=_25th_2009 q3=_75th_2009 max=Max_per100gr_sodium_mg2009;

**run**;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

So it doesn't look like the weight has an effect on the min and max, but that it does on everyother value.

proc univariate data=sashelp.bweight noprint;

var Weight;

weight MomWtGain;

output out=goofy1 min=min max=max mean=mean p10=p10 q1=q1 q3=q3;

run;

proc univariate data=sashelp.bweight noprint;

var Weight;

output out=goofy2 min=min max=max mean=mean p10=p10 q1=q1 q3=q3;

run;

proc means data=sashelp.bweight noprint;

var Weight;

weight MomWtGain;

output out=goofy3 min=min max=max mean=mean p10=p10 q1=q1 q3=q3;

run;

proc univariate data=sashelp.bweight noprint;

var Weight;

output out=goofy4 min=min max=max mean=mean p10=p10 q1=q1 q3=q3;

run;

proc sql;

create table goofy as

select distinct min, max, mean, p10, q1, q3, "Univariate no weight" as type from goofy2

union corr

select distinct min, max, mean, p10, q1, q3, "Univariate weighted" as type from goofy1

union corr

select distinct min, max, mean, p10, q1, q3, "Means no weight" as type from goofy4

union corr

select distinct min, max, mean, p10, q1, q3, "Means weighted" as type from goofy3;

However thats because a weight statement only makes that observation more valuable to the statistic, it doesn't actually change the real value of the variable. Hence the reason that the min and max never change, but the computed statistics do change. Oh and there is no difference between proc means and proc univariate outputs, thats what the above shows.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

thank you!

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Oh and apparently include QMETHOD=OS in the proc statement.

http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a000146736.htm

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.