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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

 

View solution in original post

6 REPLIES 6
art297
Opal | Level 21

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

 

Lida
Obsidian | Level 7

that was quick and easy... 🙂 thank you very much art297.

ballardw
Super User

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;
Rick_SAS
SAS Super FREQ

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. 

art297
Opal | Level 21

@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

 

Rick_SAS
SAS Super FREQ

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.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 5198 views
  • 2 likes
  • 4 in conversation