BookmarkSubscribeRSS Feed
lilyduboff
Calcite | Level 5

Hi all!

 

I am fairly new to SAS and am trying to assign specific colors to certain options in a group I have. I am trying to make a graph to show the frequency of catastrophic sport injuries that have occurred over the past few years and the event type distribution for those injuries for every state in the U.S. I have my years on the x axis and then have clustered the event types on each year. I tried using an attribute map to assign my colors and then used a macro to code for a few states at once. However, my colors are not as I assigned them, and they keep switching between states. Ideally, I am hoping to have the colors be consistent between all states. If anyone has suggestions on how to assign colors, I would greatly appreciate that! Thank you for the help in advance!

 

My code is below for my color assignment and graphing:

 

/*ASSIGNING COLORS TO DIFFERENT EVENT TYPES*/
data sreportmap2;
length ID $10 value $6 linecolor $ 9 fillcolor $ 9;
input ID $ value $ linecolor $ fillcolor $;
datalines;
BarAttr Competition/Game Green Green
BarAttr Conditioning Yellow Yellow
BarAttr Non-athletic Gray Gray
BarAttr Other Black Black
BarAttr OtherTeam Purple Purple
BarAttr Practice Orange Orange
BarAttr Scrimmage Lime Lime
BarAttr Strength/Weight Pink Pink
BarAttr Unafilliated Lightblue Lightblue
;
run;
 
/*making my graph here*/
%macro chart7 (stateM=, title=);
title "&title for &stateM";
proc sgplot data = sreport dattrmap=sreportmap2;
where state=&stateM;
vbar yearacademic / attrid=BarAttr categoryorder=respdesc group=eventtype groupdisplay=cluster;
xaxis label = "Academic Year";
yaxis label = "Frequency";
run;
%mend chart7;
 
%chart7 (stateM="Florida", title="Frequency of Catastrophic Injuries among Event Types from 2013 to 2022");
%chart7 (stateM="Ohio", title="Fatality Outcomes of Catastrophic Injuries among all Sports from 2013 to 2022");

 

3 REPLIES 3
ballardw
Super User

What are the formatted values of the group variable Eventtype?

The values in the Dattrmap data set have to match. Since your Sreportmap2 data set define the values as 6 characters long and then attempts to read value that are mostly longer than 6 I strongly suspect your values do not match those of Eventtype.

 

Example data in the form of a working data step of the Sreport data set may allow us to provide working code.

lilyduboff
Calcite | Level 5

My eventtype variable has a length of 150 and the format is "$150." The possible event types are the following: Competition/Game, Conditioning Session, Non-athletic activity, Other, Other Team activity, Practice, Scrimmage, Strength/Weight Session, Unaffiliated Recreational Activity.

 

Should I change my dattrmap to this to account for the longer length?

 

data sreportmap2;
length ID $10 value $150 linecolor $ 9 fillcolor $ 9;
input ID $ value $ linecolor $ fillcolor $;
datalines;
BarAttr Competition/Game Green Green
BarAttr Conditioning Yellow Yellow
BarAttr Non-athletic Gray Gray
BarAttr Other Black Black
BarAttr OtherTeam Purple Purple
BarAttr Practice Orange Orange
BarAttr Scrimmage Lime Lime
BarAttr Strength/Weight Pink Pink
BarAttr Unafilliated Lightblue Lightblue
;
run;

ballardw
Super User

Exact length usually does not matter but the values in the Dattrmap have be considered equal by SAS. Which means if the values of the variable Eventtype have leading spaces then the value in the Dattrmap data set would have to have leading spaces and the exact number. SAS will normally ignore trailing spaces when comparing for equality.

 

Case matters as well. If the value of the variable in the plot data set is "ABC" then the value in the Dattrmap set has to be "ABC", not "Abc" or "abc".

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 16. 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
  • 349 views
  • 0 likes
  • 2 in conversation