- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The option for changing the number of bins for a histogram in SAS University Edition does not work correctly. I tried to specify 20 bins, but the graphs only had 11 bins. What am I missing?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
For example, are you using PROC UNIVARIATE or SGPLOT or a different one?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I am using SAS University Edition.
The code is:
/*
*
* Task code generated by SAS Studio 3.71
*
* Generated on '3/8/18, 1:27 PM'
* Generated by 'sasdemo'
* Generated on server 'LOCALHOST'
* Generated on SAS platform 'Linux LIN X64 2.6.32-696.20.1.el6.x86_64'
* Generated on SAS version '9.04.01M5P09132017'
* Generated on browser 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:52.0) Gecko/20100101 Firefox/52.0'
* Generated on web client 'http://localhost:10080/SASStudio/371/main?locale=en_US&zone=GMT-07%253A00&http%3A%2F%2Flocalhost%3A10080%2FSASStudio%2F371%2F='
*
*/
ods graphics / reset width=6.4in height=4.8in imagemap;
proc sgplot data=WORK.DATA1;
histogram x1 / nbins=20;
yaxis grid;
run;
ods graphics / reset;
The log is:
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I think there's more bins they're just really really small.
You'll get better control if you control the start and end instead.
There's also a note in the documentation about how it's not always what you expect.
NBINS=numeric-value
specifies the number of bins. The system determines the BINWIDTH= value. The bins always span the range of the data.
The procedure attempts to produce tick values that are easily interpreted (for example, 5, 10, 15, 20). The procedure sometimes adjusts the location of the first bin and the bin width accordingly. As a result, the number of bins shown in the plot might not exactly match the number specified with NBINS=.
You can see the exact data used, with the data set below:
ods output sgplot=myBins;
proc sgplot data=sashelp.cars ;
histogram mpg_highway / nbins=20;
run;
proc print data=myBins;
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
I specified the max and min values for the data. The data are 500 uniform random (-1,1) deviates.
The result is the same - 11 bars.
The code is:
ods graphics / reset width=6.4in height=4.8in imagemap;
proc sgplot data=WORK.DATA1;
histogram x1 / nbins=20;
xaxis min=-1 max=1;
yaxis grid;
run;
ods graphics / reset;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This works for me:
proc sgplot data=sashelp.cars ;
histogram mpg_highway / binstart=10 binwidth=10 ;
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
Does your log say anything about the NBINS not being honored?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@WilliamBoecklen wrote:
I specified the max and min values for the data. The data are 500 uniform random (-1,1) deviates.
The result is the same - 11 bars.
The code is:
ods graphics / reset width=6.4in height=4.8in imagemap;
proc sgplot data=WORK.DATA1;
histogram x1 / nbins=20;
xaxis min=-1 max=1;
yaxis grid;
run;
ods graphics / reset;
Xaxis really doesn't have much to do with the bin assignments. It may cutoff bins or create a lot of unused axis in relation to the shown bins and will effect the displayed width of the bins thereby.