I am relatively new to graphing in SAS, but am finding it great to have the level of control it provides. I have succeeded in making a box and whisker plot that meets all my specifications, but one. I have 8 groups (4 classes of each of two groups). I want the boxes of one group to be red, the other to be blue. Group 1 is values 1.0, 2.0, etc. Group 2 is 1.3, 2.3 etc. I want group 1 to be red, group 2 to be blue. I have searched, but have not seen a way to change color of individual boxes. I'm sure there is a more elegant way to do what I want, but would appreciate knowing how to control color of individual box and whisker displays, given the code I have thus far.
label ma_rg_ach_level_mb09 = "Math 2009 Achievement Level"
new_abc_math_g = "Math 2010 Growth";
if grade = '04' or grade = '05';
if ma_rg_ach_level_mb09 = 'NULL' then ma_rg_ach_level_mb09 = ' ';
if ma_rg_ach_level_mb09 = 1 and SWD = 'N' then group = 1.0;
if ma_rg_ach_level_mb09 = 1 and SWD = 'Y' then group = 1.3;
if ma_rg_ach_level_mb09 = 2 and SWD = 'N' then group = 2.0;
if ma_rg_ach_level_mb09 = 2 and SWD = 'Y' then group = 2.3;
if ma_rg_ach_level_mb09 = 3 and SWD = 'N' then group = 3.0;
if ma_rg_ach_level_mb09 = 3 and SWD = 'Y' then group = 3.3;
if ma_rg_ach_level_mb09 = 4 and SWD = 'N' then group = 4.0;
if ma_rg_ach_level_mb09 = 4 and SWD = 'Y' then group = 4.3;
ods graphics on;
value = dot
height = 0.4
interpol = boxtf
width = 3
bwidth = 5
co = BL
cv = VLIGB
mode = include;
order = (-3, -2, -1, 0, 1, 2, 3)
label = (f= "Arial/Bold" height = 2.25 angle = 90 'Mathematics Growth Score 2010')
minor = (number = 1)
value = (f= "Arial" height = 1.75)
width = 2
color = black;
label = (f= "Arial/Bold" height = 2.25 'Math Proficiency Level 2009')
offset = (5, 5)
value = (f= "Arial" height = 1.75);
proc gplot data = temp
plot new_abc_math_g*group /
haxis = axis2
vaxis = axis1
hminor = 0
Thank you, those changes did indeed produce two different colored box plots. Because both groups are represented in the four categories on the abscissa, the two sets of box plots sit right on top of one another with these changes. I need to offset them from the tick marks so one can see both sets of boxes. I am now playing with my options to get that done. I've tried switching to a numeric variable on the abscissa and changing values of two groups slightly (e.g., 1 becomes .8 for one group and 1.2 for the other group). I guess my other option is to overlay one graph on top of the other with an offset.
I would try making more noticeable changes in the horizontal axis values and possibly adjust the AXIS statement to control tickmarks and such. Also you don't have a units specified for Width or Bwidth in the symbol statement. You may want to use a unit like bwidth=.2in or similar to get finer control of actual widths as the default is Cells which can be largish for some displays.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.