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:
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.?
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
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
Thanks, @DanH_sas , I have used discrete attribute maps in the past and totally forgot about them. But this works!
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.