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


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
BuckyRansdell
SAS Employee

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.

View solution in original post

5 REPLIES 5
AncaTilea
Pyrite | Level 9

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!


box_plot_clipped.png
GraphGuy
Meteorite | Level 14

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.

xian
Calcite | Level 5

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?

BuckyRansdell
SAS Employee

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.

xian
Calcite | Level 5

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.

sas-innovate-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1584 views
  • 0 likes
  • 4 in conversation