Using this code:
title "Bubble plot by Sex";
proc sgplot data=sashelp.class;
bubble x=height y=weight size=age / group=sex;
run;
Is there a way to assign a specific color to each level in the sex column (e.g. male=green, female=red)
If you know the order of the categories and you only want to do this one time, you can use the STYLEATTRS statement:
proc sgplot data=sashelp.class;
styleattrs datacolors=(blue pink);
bubble x=height y=weight size=age / group=sex;
run;
For more complicated scenarios, discrete data maps are more powerful and flexible, as Warren said.
https://blogs.sas.com/content/graphicallyspeaking/2013/04/02/attribute-maps-1/
Discrete attribute maps.
If you know the order of the categories and you only want to do this one time, you can use the STYLEATTRS statement:
proc sgplot data=sashelp.class;
styleattrs datacolors=(blue pink);
bubble x=height y=weight size=age / group=sex;
run;
For more complicated scenarios, discrete data maps are more powerful and flexible, as Warren said.
Please post your log where the error appear?
The STYLEATTRS statement was added in SAS 9.4. , so if you are running an old version of SAS you would get an error like you are seeing.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.