BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
csetzkorn
Lapis Lazuli | Level 10

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)

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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.

View solution in original post

6 REPLIES 6
Rick_SAS
SAS Super FREQ

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.

csetzkorn
Lapis Lazuli | Level 10
thanks - Warren's suggestion is great but probably overkill for my situation. I am getting ERROR 180-322: Statement is not valid or it is used out of proper order. when I add the line styleattrs ... any ideas?
PeterClemmensen
Tourmaline | Level 20

Please post your log where the error appear?

Rick_SAS
SAS Super FREQ

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.

csetzkorn
Lapis Lazuli | Level 10
OK thanks makes sense. I will run this in the newer env.

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