Graphics Programming

Data visualization using SAS programming, including ODS Graphics and SAS/GRAPH. Charts, plots, maps, and more!
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-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
  • 539 views
  • 0 likes
  • 4 in conversation