turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Histogram for weighted values

Topic Options

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-04-2017 03:01 PM

Hello,

Proc univariate does not support weight statement to build a histogram. Is there any other procedure that can be used to build a histogram for weighed values? Thank you!

Accepted Solutions

Solution

08-04-2017
03:37 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Lida

08-04-2017 03:10 PM

Interestingly, while it doesn't support the weight statement, it does appear to support the freq statement. e.g.,

data have; input score weight; cards; 1 2 2 3 3 4 4 5 5 6 6 5 7 4 8 3 9 2 ; proc univariate data=have noprint; histogram score; freq weight; run;

Art, CEO, AnalystFinder.com

All Replies

Solution

08-04-2017
03:37 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Lida

08-04-2017 03:10 PM

Interestingly, while it doesn't support the weight statement, it does appear to support the freq statement. e.g.,

data have; input score weight; cards; 1 2 2 3 3 4 4 5 5 6 6 5 7 4 8 3 9 2 ; proc univariate data=have noprint; histogram score; freq weight; run;

Art, CEO, AnalystFinder.com

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to art297

08-04-2017 03:37 PM

that was quick and easy... :-) thank you very much art297.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Lida

08-04-2017 03:18 PM

Depending on numbers of levels you want you might try Proc Freq and request a FreqPlot. Heres a crude and somewhat nonsensical in real terms but generates bars using weights.

ods graphics on; proc freq data=sashelp.class; weight age; tables weight/plots=freqplot; run; ods graphics off;

If you have a continuous variable with many levels you might use a custom format to create bins.

Or Proc SGPlot and a histogram plot.

proc sgplot data=sashelp.class; histogram height / weight = age; run;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Lida

08-07-2017 10:18 AM

A weight variable is not the same as a frequency variable. A data set that has 10 observations and a frequency variable might represent 100s of observations. A data set that has 10 observations and a weight variable represents 10 data points where each observation has different influence in the analysis.

You accepted Art's answer, so should we assume that you meant "frequency-replicated observations" instead of weighted observations? If so, please consider changing the title.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rick_SAS

08-07-2017 10:40 AM

@Rick_SAS: Is there any difference with respect to producing a histogram (other than the freq variable has to be integers?)

Art, CEO, AnalystFinder.com

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to art297

08-07-2017 01:26 PM

That's a good question, Art. **If** the weights are positive integers and if you specify the bandwidth, then I think the histograms will be the same on the density scale. However, most histogram algorithms use an automated binning algorithm that chooses bins based on the number of observations, N. Since N for the frequency case isn't the same as N for the weighted case, you might get different bin widths from the automated binning algorithm. Theoretically, a frequency variable will result in smaller bin widths because there are more observations.