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

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? 30886-23840 = 7046

title "Snacks test - All Qtysold bins 0 to 10";
proc sgplot data=sashelp.snacks;
   histogram qtysold/datalabel=count scale=percent showbins binstart=0 binwidth=10 boundary=lower;
run;
title "qtysold <11";
proc means data=sashelp.snacks(where=(0 le qtysold le 10)) n nmiss min p25 median p75 max mean ;
   var qtysold;
run;

 

 

SGPlot histogram error.png
 
SAS Output
qtysold <11

The MEANS Procedure

 

Analysis Variable : QtySold Quantity sold
N N Miss Minimum 25th Pctl Median 75th Pctl Maximum Mean
308860002.00000005.000000010.0000000

2.9644464

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Steve_SAS
Fluorite | Level 6
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 - non-integers 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.

View solution in original post

4 REPLIES 4
ballardw
Super User

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 mid-point of the 5-15 range.

If you really have to force displays to intervals of 0-10, 10-20 then use VBAR and a format to create ranges for the xaxis variable.

Steve_SAS
Fluorite | Level 6
Why are zero values of qtysold ignored on histogram? Where is the first bin controlled so it is 5 to 15? What about 0,1,2,3,4 values?
Steve_SAS
Fluorite | Level 6
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 - non-integers 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.

ballardw
Super User

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1191 views
  • 0 likes
  • 2 in conversation