Help using Base SAS procedures

Unexpected Results with PROC BOXPLOT

Reply
Contributor
Posts: 22

Unexpected Results with PROC BOXPLOT

I would like to create a boxplot to compare the distributions between two values of a categorical variable. I would like to use PROC BOXPLOT to take advantage of the INSETGROUP statement and display univariate statistics for each value.

 

The code I'm using is:

 

PROC BOXPLOT DATA=&dsn;

BY &age_bucket;

PLOT mileage*fuel / MAXPANELS=100;

RUN;

 

I used the MAXPANELS= option because I initially got an error stating the number of panels needed is 97 and I can alter the default with the MAXPANELS= option. However, even after adding it, I get unexpected results. The categorical variable fuel only has two values, so I'm expected to boxplots on one panel with this code (for each age_bucket). 

 

Can someone explain why this is not happening and I'm getting instead dozens of boxplots across repeated values of the categorical variable fuel

 

Thanks in advance for any assistance. 

 

Dhrumil

Super User
Posts: 11,343

Re: Unexpected Results with PROC BOXPLOT

Posted in reply to dhrumil_patel

Show some example data.

And some of the output.

And what does the macro variable &age_bucket resolve to? I would normally expect a single variable that has values of age or the age group and do not see why a macro variable was needed. Unless your "age_bucket" is consisting fo multiple variables in which case that will go a long way to explaining many plots.

Contributor
Posts: 22

Re: Unexpected Results with PROC BOXPLOT

Yes. Thanks for the clarification.

 

Example data and output are attached. 

 

Sorry, I misstated in that age_bucket is not a macro variable, just a variable:

 


proc boxplot data=&dsn;
by age_bucket;
plot kms*fuel_vims / maxpanels=100;
run;


example_output.PNG
Contributor
Posts: 22

Re: Unexpected Results with PROC BOXPLOT

Posted in reply to dhrumil_patel

example_data.PNG
Super User
Posts: 11,343

Re: Unexpected Results with PROC BOXPLOT

Posted in reply to dhrumil_patel

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

Note that the picture of your output really isn't possible with the code you've shown. As a minimum there may be a Title statment missing.

But with your "title" showing "FUEL=Diesel" and all of the horizontal axis values of "gasolina" I suspect there is something else you haven't shown.

Super User
Posts: 19,822

Re: Unexpected Results with PROC BOXPLOT

Posted in reply to dhrumil_patel

Run a proc freq on your FUEL variable with NO formats. I suspect you have an underlying format that may be causing the issue. 

 

proc freq data=have;
table fuel;
format fuel;
run;
Ask a Question
Discussion stats
  • 5 replies
  • 337 views
  • 0 likes
  • 3 in conversation