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

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;


FrequencyTable - promtime variable.JPGHistogram -promtime variable.JPG
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

What does your log say? 

Exclude your outlier with a WHERE statement instead. 

View solution in original post

6 REPLIES 6
Reeza
Super User

What does your log say? 

Exclude your outlier with a WHERE statement instead. 

smajid
Obsidian | Level 7
Oh wow, thanks, Reeza! The 'where statement' solution worked.

I really appreciate your prompt response.
Ksharp
Super User
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;


smajid
Obsidian | Level 7
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!!
Ksharp
Super User

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;

Reeza
Super User

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;

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!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

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