BookmarkSubscribeRSS Feed
lilyduboff
Calcite | Level 5

Hi everyone, 

 

I am creating graphics depicting trends of catastrophic sport injuries in all U.S. states. I want to make sure my colors are consistent for each scenario and state.

 

In one of my vbar graphs, I am showing injuries by sport and sex. I want to make sure athletesex will be blue for male and red for female. Additionally, I want to make sure that the blue bar showing males appears on the left side of the red. Right now, I think SAS is automatically putting the one with a higher value to the left, and I do not want that. My code is below. 

 

proc sgplot data=sreportlabels;
title "Frequency of Catastrophic Sport Injuries by Sport and Sex in Alabama (2013-2022)";
vbar injurysport / group=athletesex groupdisplay=Cluster;
xaxis label = "Sport";
yaxis label = "Frequency" values = (0 to 20 by 5);
where state = "Alabama";
run;

 

lilyduboff_0-1721833588918.png

Thank you for the help!

 

3 REPLIES 3
PaigeMiller
Diamond | Level 26

You probably want to use the GROUPORDER=DESCENDING option of the VBAR statement to force males to come first.

 

To force the colors to be something specific and unchanging, you can use a discrete attribute map.

--
Paige Miller
Madelyn_SAS
SAS Super FREQ

This is the reply from @PaigeMiller before this was moved to the Graphics Programming community. 

You need to create and use a discrete attribute map.

 

Example: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/n18szqcwir8q2nn10od9hhdh2ksj.htm

Ksharp
Super User
Alternative way is sorting your data before PROC SGPLOT like:

proc sort data=sreportlabels;
by sex;
run;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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