Turn on suggestions

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

Showing results for

- Home
- /
- Programming
- /
- Graphics
- /
- Help with boxplot clipping

Options

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

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 10-27-2012 10:31 AM
(1583 views)

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;

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

5 REPLIES 5

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

**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.

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.