Programming the statistical procedures from SAS

Issues with Bins in Histogram

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

Issues with Bins in Histogram

Hi,

 

I am a newbie, who is using proc univariate to create a histogram but I'm having issues. My problem is that all the observations are bunched up under one bin/bar. Can anyone please guide me what could be the issue? Thank you in advance for your help!

Regards

Saulat

 

========

  • I'm trying to create a histogram for a variable "promtime", which has a range of 0 to 14034. However, the value 14034 is an outlier and if I exclude that, the range is 0 to 39. I tried to do that via "endpoints" option in the "histogram" statement but it doesn't work.
  • My code is below. I suspect that the "goptions" statement is causing problems but not sure about that.
  • The output of the "proc freq" and histogram chart are attached.

 

Code:

***Temporary setting default values for graphics attributes***;
goptions reset=global /*Cancels all global statements */
gunit=pct /*Specifies the default unit of measure to be Percent, which to be used with height specifications.*/
hsize= 10.625 in /*Sets horizontal heigh of graphic area */
vsize= 8.5 in /*Sets vertical heigh of graphic area */
htitle=4 /*Selects the default height (default percent) used for the first TITLE line.*/
htext=3 /*Specifies the default height of the text in the graphics output. */
vorigin=0 in /*Sets vertical origin of graph */
horigin= 0 in /*Sets horizonal origin of graph */
cback=white border /*Background color of graph is set to white */
ctext=black /*Text color is black*/
colors=(black blue green red yellow) /*Specifies the foreground colors used to produce your graphics output*/
ftext=swiss /*Default font for all text*/
lfactor=3; /*Line Thickness */

 

***Check***;
proc freq data =Project1.Org ;
tables promtime;
run;

 

proc univariate data=Project1.Org noprint;
histogram promtime
/ endpoints = 0 to 39;
run;

Attachment
Attachment

Accepted Solutions
Solution
‎10-03-2016 09:24 AM
Grand Advisor
Posts: 16,926

Re: Issues with Bins in Histogram

What does your log say? 

Exclude your outlier with a WHERE statement instead. 

View solution in original post


All Replies
Solution
‎10-03-2016 09:24 AM
Grand Advisor
Posts: 16,926

Re: Issues with Bins in Histogram

What does your log say? 

Exclude your outlier with a WHERE statement instead. 

Occasional Contributor
Posts: 14

Re: Issues with Bins in Histogram

Oh wow, thanks, Reeza! The 'where statement' solution worked.

I really appreciate your prompt response.
Grand Advisor
Posts: 9,466

Re: Issues with Bins in Histogram

1) specify step width.

data class;
 set sashelp.class end=last;
 output;
 if last then do;age=30;output;end;
run;

proc univariate data=class;
 var age;
 histogram age/ endpoints=(0 to 30 by 1) ;
run;


2) Your data is discrete not continuous, it is not good for Histogram, but for VBAR chart.

proc sgplot data=class;
 vbar age/ stat=percent;
run;


Occasional Contributor
Posts: 14

Re: Issues with Bins in Histogram

Thanks, Ksharp! I tried Reeza's solution first, it solved the issue. But I sure will see if this works. Thanks a lot for your help too.

I love SAS Communities!!
Grand Advisor
Posts: 9,466

Re: Issues with Bins in Histogram


data class;
 set sashelp.class end=last;
 output;
 if last then do;age=30;output;end;
run;

proc univariate data=class;
 var age;
 histogram age/ endpoints=(0 to 30 by 1) rtinclude ;
run;

Grand Advisor
Posts: 16,926

Re: Issues with Bins in Histogram

ENDPOINTS & MIDPOINTS must cover the full interval otherwise SAS ignores it. There will be a message in the log to that effect. 

So, exclude your outliers with a WHERE statement. 

 

Where variable< 10000;
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 281 views
  • 3 likes
  • 3 in conversation