BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PaigeMiller
Diamond | Level 26
proc sort data=sashelp.class out=class;
	by sex;
run;
proc sgplot data=class;
styleattrs;
	by sex;
    vbox height/group=age grouporder=ascending;
run;

produces this result:

 

Capture.PNG

How can I do this so that the color for 11 year olds is the same on each plot, and the color for 12 year olds is the same on each plot, etc.?

--
Paige Miller
1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

Just use a discrete attributes map, like the following:

 

proc sort data=sashelp.class out=class;
	by sex;
run;

data attrmap;
retain id "myid" linecolor "black";
length fillcolor $ 6;
input value $ fillcolor $;
cards;
11 orange
12 purple
13 green
14 blue
15 red
16 gold
;
run;

proc sgplot data=class dattrmap=attrmap;
  by sex;
  vbox height/group=age attrid=myid grouporder=ascending;
run;

 

Hope this helps!

Dan 

View solution in original post

3 REPLIES 3
DanH_sas
SAS Super FREQ

Just use a discrete attributes map, like the following:

 

proc sort data=sashelp.class out=class;
	by sex;
run;

data attrmap;
retain id "myid" linecolor "black";
length fillcolor $ 6;
input value $ fillcolor $;
cards;
11 orange
12 purple
13 green
14 blue
15 red
16 gold
;
run;

proc sgplot data=class dattrmap=attrmap;
  by sex;
  vbox height/group=age attrid=myid grouporder=ascending;
run;

 

Hope this helps!

Dan 

PaigeMiller
Diamond | Level 26

Thanks, @DanH_sas , I have used discrete attribute maps in the past and totally forgot about them. But this works!

--
Paige Miller
ballardw
Super User

If your group variable within levels of the by variable have the same minimum and the same values except for possibly max then a modification to sort works:

proc sort data=sashelp.class out=class;
	by sex age;
run;

proc sgplot data=class;
styleattrs;
	by sex;
    vbox height/group=age grouporder=ascending;
run;

but when there are differing gaps in the values of the group variable the color no longer aligns.

 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2456 views
  • 0 likes
  • 3 in conversation