Using SAS 9.04.01 M3 on Windows 7, with EG 7.1 on a Linux Grid.
Counts are off by 7046 on first bin of histogram as compared to proc means. Values are 0 to 10. What am I missing? 3088623840 = 7046

qtysold <11 
30886  0  0  0  2.0000000  5.0000000  10.0000000  2.9644464

title "Snacks test Scale=pct Qtysold bins 0 to 10";
proc sgplot data=sashelp.snacks(where=(0 le qtysold le 100));
histogram qtysold/datalabel=count showbins scale=percent binstart=5 binwidth=10 boundary=lower;
run;
title "qtysold <=10";
proc means data=sashelp.snacks(where=(0 le qtysold le 10)) n nmiss min p25 median p75 max mean ;
var qtysold;
run;
title "qtysold 11? to 20  nonintegers in qtysold variable";
proc means data=sashelp.snacks(where=(10 lt qtysold le 20)) n nmiss min p25 median p75 max mean ;
var qtysold;
run;
This works. I'm still not sure how to control the first bin.
The boundaries used for this histogram with your options are 5, 15, 25, 35. Binstart does not actually set a boundary, it more associated with the displayed x value which would be the center of the bar range shown. Hence 10 is midpoint of the 515 range.
If you really have to force displays to intervals of 010, 1020 then use VBAR and a format to create ranges for the xaxis variable.
title "Snacks test Scale=pct Qtysold bins 0 to 10";
proc sgplot data=sashelp.snacks(where=(0 le qtysold le 100));
histogram qtysold/datalabel=count showbins scale=percent binstart=5 binwidth=10 boundary=lower;
run;
title "qtysold <=10";
proc means data=sashelp.snacks(where=(0 le qtysold le 10)) n nmiss min p25 median p75 max mean ;
var qtysold;
run;
title "qtysold 11? to 20  nonintegers in qtysold variable";
proc means data=sashelp.snacks(where=(10 lt qtysold le 20)) n nmiss min p25 median p75 max mean ;
var qtysold;
run;
This works. I'm still not sure how to control the first bin.
If you actually want a vertical bar chart with the width at points you control then use VBAR and a format to create groups
proc format library=work; value bins 0  10 = ' 0' 10 < 20 = '10' 20 < 30 = '20' 30 < 40 = '30' 40 < 50 = '40' 50 < 60 = '50' 60 < 70 = '60' 70 < 80 = '70' 80 < 90 = '80' 90 <100 = '90' ; run; proc sgplot data=sashelp.snacks(where=(0 le qtysold le 100)); vbar qtysold/stat=freq datalabel; format qtysold bins.; run;
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.
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.