BookmarkSubscribeRSS Feed
WilliamBoecklen
Fluorite | Level 6

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?

9 REPLIES 9
Reeza
Super User
For us to tell what’s missing we need to see what you have. Please post your code and log.

For example, are you using PROC UNIVARIATE or SGPLOT or a different one?
WilliamBoecklen
Fluorite | Level 6

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:

 

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
NOTE: ODS statements in the SAS Studio environment may disable some output features.
73
74 /*
75 *
76 * Task code generated by SAS Studio 3.71
77 *
78 * Generated on '3/8/18, 1:27 PM'
79 * Generated by 'sasdemo'
80 * Generated on server 'LOCALHOST'
81 * Generated on SAS platform 'Linux LIN X64 2.6.32-696.20.1.el6.x86_64'
82 * Generated on SAS version '9.04.01M5P09132017'
83 * Generated on browser 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:52.0) Gecko/20100101 Firefox/52.0'
84 * Generated on web client
84 ! 'http://localhost:10080/SASStudio/371/main?locale=en_US&zone=GMT-07%253A00&http%3A%2F%2Flocalhost%3A10080%2FSASStudio%2F3
84 ! 71%2F='
85 *
86 */
87
88 ods graphics / reset width=6.4in height=4.8in imagemap;
89
90 proc sgplot data=WORK.DATA1;
91 histogram x1 / nbins=20;
92 yaxis grid;
93 run;
 
NOTE: PROCEDURE SGPLOT used (Total process time):
real time 4.79 seconds
cpu time 0.21 seconds
 
WARNING: The font <sans-serif> is not available. Albany AMT will be used.
WARNING: The font <sans-serif> is not available. Albany AMT will be used.
NOTE: There were 500 observations read from the data set WORK.DATA1.
 
94
95 ods graphics / reset;
96
97 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
110
 
The result is a histogram with 11 bars
 
 
Reeza
Super User

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;
WilliamBoecklen
Fluorite | Level 6

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;

Reeza
Super User

This works for me:

proc sgplot data=sashelp.cars ;
histogram mpg_highway / binstart=10 binwidth=10 ;
run;
WilliamBoecklen
Fluorite | Level 6
Thank for the response. I am teaching a biometry course and I chose SAS Studio to avoid programing. I wanted the students to have a point and click interface. Unfortunately the point and click options do not work.
DanH_sas
SAS Super FREQ

Does your log say anything about the NBINS not being honored?

ballardw
Super User

@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.

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 9 replies
  • 13040 views
  • 0 likes
  • 4 in conversation