turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS/GRAPH and ODS Graphics
- /
- Help with boxplot clipping

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

10-27-2012 10:31 AM

Hi,

Since ODS graphics boxplot does not support clipping, I'm trying to manually calculate the clipping range and change the boxplot template to add an overlay plot for the clipping range. I'm following the formula here: http://support.sas.com/documentation/cdl/en/statug/63347/HTML/default/viewer.htm#statug_boxplot_sect.... With the data provided in the example, the clipping ranges I computed seem to match the values on the plot. But when I used a different data set, I got very different results. Here's my code. Can someone help me understand what's causing the difference? Thanks!

proc sort data=sashelp.cars out=cars(keep=make horsepower);

by make;

where make < 'L';

run;

/* ============== manual calculation ==================*/

proc means data=cars q1 q3 nway missing noprint;

class make;

var horsepower;

output out=cars_sum (drop=_freq_ _type_) q1=grp_q1 q3=grp_q3;

run;

proc means data=cars_sum mean nway missing noprint;

var grp_q1 grp_q3;

output out=all_sum(drop=_freq_ _type_) mean=grp_q1_mean grp_q3_mean;

run;

data all_sum;

set all_sum;

ymax = grp_q1_mean + (grp_q3_mean - grp_q1_mean) * 1.5;

ymin = grp_q3_mean - (grp_q3_mean - grp_q1_mean) * 1.5;

run;

/* =================== get results from boxplot ============== */

ods graphics off;

proc boxplot data=cars;

plot horsepower * make /clipfactor=1.5;

run;

Accepted Solutions

Solution

10-30-2012
11:07 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to xian

10-30-2012 11:07 AM

Hi Xian,

You are doing the calculations correctly. The clipping range only determines which data points are ignored for vertical axis scaling. After the clipping range is established, PROC BOXPLOT scales the vertical axis to provide "nice" tick mark values. So the clipped data range from 149 to 308 results in tick marks from 100 to 350 by 50. You can use the PLOT statement VAXIS= option to specify a tighter range, for example 140 to 310 by 10.

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to xian

10-27-2012 08:38 PM

Hi Xian,

I ran your code in SAS 9.3 and it ran great.

I added a couple of options as I saw in the reference you suggested.

**proc boxplot data=cars;**

** plot horsepower * make /**** clipfactor=1.5**** clipsymbol = dot**** cliplegpos = top**** cliplegend = '# Clipped Boxes'**** clipsubchar = '#'**** ;****run;**

Are you using SAS 9.2 or 9.3?

One thing I noticed, and your code already has it, it was the ODS Graphics OFF statement, which I did not have initially (But you did).

Not sure what to say.

If this doesn't work for you, you could use proc gplot with the symbol i = boxNN options where "NN" will tell SAS what percent of data to display...eeeh, say i = Box20 will have the lower bound at 20 percentile and the high bound at 80 percentile.

Best of luck!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to xian

10-29-2012 08:22 AM

Xian - are you intentionally turning ods graphics off for a specific reason?

If you turn ods graphics off, I believe Proc Boxplot reverts back to a "pre- ods graphics" boxplot (which is created using the SAS/Graph graphics libraries, I believe -- Proc Boxplot is not a SAS/GRAPH proc per-say, but prior to ods graphics there was some "overlap"). Probably the best way to go, for the most flexibility & functionality for Proc Boxplot, is to use ods graphics.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to RobertAllison_SAS

10-29-2012 03:21 PM

I actually wanted to turn graphics on. But if I turn it on, the clipping will not work. What I don't understand is that the clipping range proc boxplot gave me is different from what I got from manual calculation. For this example. The boxplot shows clipping range of 100 - 350. But I got a clipping range of 149 - 308. Is my manual calculation wrong?

Solution

10-30-2012
11:07 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to xian

10-30-2012 11:07 AM

Hi Xian,

You are doing the calculations correctly. The clipping range only determines which data points are ignored for vertical axis scaling. After the clipping range is established, PROC BOXPLOT scales the vertical axis to provide "nice" tick mark values. So the clipped data range from 149 to 308 results in tick marks from 100 to 350 by 50. You can use the PLOT statement VAXIS= option to specify a tighter range, for example 140 to 310 by 10.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to BuckyRansdell

11-01-2012 04:09 PM

Thanks BuckyRansdell! You are correct. The ymax and ymin are not the final ymax and ymin on the chart. They are determined by SAS auto scaling algorithm.