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:
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.
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;
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".
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!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: