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

Hello,

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.

Thank you.

data temp;

set grant.ayp2010w2009_2;

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;

proc sort;

by group;

ods graphics on;

title ;

symbol

value = dot

height = 0.4

interpol = boxtf

width = 3

bwidth = 5

co = BL

cv = VLIGB

mode = include;

axis1

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;

axis2

label = (f= "Arial/Bold" height = 2.25 'Math Proficiency Level 2009')

offset = (5, 5)

value = (f= "Arial" height = 1.75);

proc gplot data = temp

uniform ;

plot new_abc_math_g*group /

haxis = axis2

vaxis = axis1

hminor = 0

skipmiss ;

run;

quit;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

You might try adding a variable for colorgroup or some such.

Then the plot statement becomes

plot new_abc_math_gr*group=colorgroup

And add a symbol2 statement with the color changes.

View solution in original post

4 REPLIES 4
ballardw
Super User

You might try adding a variable for colorgroup or some such.

Then the plot statement becomes

plot new_abc_math_gr*group=colorgroup

And add a symbol2 statement with the color changes.

acschul3
Fluorite | Level 6

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. 

DanH_sas
SAS Super FREQ

I'm not sure of your SAS version, but the boxplot you describe it simple to do with PROC SGPLOT. Try this example and see if it works for you:

proc sgplot data=sashelp.cars;

vbox mpg_city / category=origin group=type;

run;

ballardw
Super User

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 1759 views
  • 0 likes
  • 3 in conversation