BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
chelseaxxlutz
Obsidian | Level 7

Hello all,

 

This is a follow up to my post about a week ago creating a heat map using HEATMAPPARM to generate a discrete legend. Using the below code, I finally have the exact graph I want.... almost. It appears that by using an attribute map, I am no longer able to apply my formats? Below are my images and code. The teal-brown-purple graph has the correct formats applied, but the colors don't work. The yellow-orange-red one is the color I want, but my legend does not have the format. Would anyone know why these two pieces of code don't want to work together? I am using SAS 9.4 Thank you!

 

Code WITH format that produces wrong colors:

/*formats for skill bin labels*/
proc format;
value sb
	   1="0.01-0.05"
	   2="0.05-0.20"
	   3="0.20-0.35"
	   4="0.35-0.50"
	   5="0.50-1.00";
run;


/*create attribute map for cell colors*/
data Attrs;
length Value 8. FillColor $20;
ID = "skill_bin";
Value = 1; FillColor="cxFFFF66"; output;
Value = 2; FillColor="cxFFCC00"; output;
Value = 3; FillColor="cxFF9900"; output;
Value = 4; FillColor="cxCC3300"; output;
Value = 5; FillColor="cx910014"; output;
run;


/*create heat map for each state/territory of ensemble peak week skill and number of weeks pre/post peak week*/
title "State-specific ensemble model skill for peak week, relative to observed peak week, per state/territory";
ods graphics / height=1100px width=900px;
proc sgplot data=heatmap dattrmap=Attrs;
   heatmapparm x=relative_wk y=territory colorgroup=skill_bin / attrid=skill_bin outline discretex discretey;
   keylegend  / title="Ensemble Peak Week Forecast Skill" across=5 sortorder=ascending titleattrs=(size=8) valueattrs=(size=8);
   xaxis type=discrete label="Week Relative to Observed Peak Week" labelattrs=(size=8 weight=bold) valueattrs=(size=8);
   yaxis type=discrete label="State/Territory" labelattrs=(size=8 weight=bold) valueattrs=(size=8);
   format Skill_bin sb. location loc.; 
run;

wrong1.png

 

 

Code WITHOUT format that produces correct colors, but I lose my legend labels:

/*formats for skill bin labels and state/territory names*/
proc format;
value sb
	   1="0.01-0.05"
	   2="0.05-0.20"
	   3="0.20-0.35"
	   4="0.35-0.50"
	   5="0.50-1.00";
run;


/*create attribute map for cell colors*/
data Attrs;
length Value 8. FillColor $20;
ID = "skill_bin";
Value = 1; FillColor="cxFFFF66"; output;
Value = 2; FillColor="cxFFCC00"; output;
Value = 3; FillColor="cxFF9900"; output;
Value = 4; FillColor="cxCC3300"; output;
Value = 5; FillColor="cx910014"; output;
run;


/*create heat map for each state/territory of ensemble peak week skill and number of weeks pre/post peak week*/
title "State-specific ensemble model skill for peak week, relative to observed peak week, per state/territory";
ods graphics / height=1100px width=900px;
proc sgplot data=heatmap dattrmap=Attrs;
   heatmapparm x=relative_wk y=territory colorgroup=skill_bin / attrid=skill_bin outline discretex discretey;
   keylegend  / title="Ensemble Peak Week Forecast Skill" across=5 sortorder=ascending titleattrs=(size=8) valueattrs=(size=8);
   xaxis type=discrete label="Week Relative to Observed Peak Week" labelattrs=(size=8 weight=bold) valueattrs=(size=8);
   yaxis type=discrete label="State/Territory" labelattrs=(size=8 weight=bold) valueattrs=(size=8);
run;

wrong2.png

 

This one really has me stuck. Is it something as simple as the format needs to go in the attribute map? I admit I'm not very familiar with making one. Thank you in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

The attribute maps should refer to the FORMATTED values. Those are the values that determine the groups:

 

/*create attribute map for cell colors*/
data Attrs;
length Value $10 FillColor $15;
input raw FillColor;
Value = put(raw, SB.);            /* use format to assign values */
retain ID "skill_bin";
datalines;
1 cxFFFF66
2 cxFFCC00
3 cxFF9900
4 cxCC3300
5 cx910014
;

When you use a discrete attribute map, you shouldn't need the SORTORDER= option on the KEYLEGEND statement.

View solution in original post

2 REPLIES 2
Rick_SAS
SAS Super FREQ

The attribute maps should refer to the FORMATTED values. Those are the values that determine the groups:

 

/*create attribute map for cell colors*/
data Attrs;
length Value $10 FillColor $15;
input raw FillColor;
Value = put(raw, SB.);            /* use format to assign values */
retain ID "skill_bin";
datalines;
1 cxFFFF66
2 cxFFCC00
3 cxFF9900
4 cxCC3300
5 cx910014
;

When you use a discrete attribute map, you shouldn't need the SORTORDER= option on the KEYLEGEND statement.

chelseaxxlutz
Obsidian | Level 7

And @Rick_SAS you save the day again! Thank you very much!

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
  • 2 replies
  • 806 views
  • 1 like
  • 2 in conversation