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

Hi all,

 

I'm a relatively new SAS user using 9.4, so please excuse my naivety of SAS and its vernacular. I'm trying to make a Heat Map using Proc Template and I'm 99% of the way there. My data are in a three-column table; the first two columns are X and Y values, while the third is a number between 0 and 6. My current problem is the colorresponse bar at the right. It automatically scales itself so the minimum and maximum values are the minimum and maxima of my data, respectively. Instead, I'd like the minimum to be 0 and the maximum to be 20. I've included my template and Proc Sgrender statements below in case those help.

 

Thanks!

 

 

proc template; /* basic heat map with continuous color ramp */
define statgraph heatmap2;
dynamic _X _Y _Z _T; /* dynamic variables */
begingraph;
entrytitle _T; /* specify title at run time (optional) */
layout overlay;
heatmapparm x=_X y=_Y colorresponse=_Z / /* specify variables at run time */
name="heatmap" primary=true
COLORMODEL = (BLUE LIME GREEN RED)
xbinaxis=false ybinaxis=false;
range 0 - 20;
continuouslegend "heatmap";
endlayout;
endgraph;
end;
run;

proc sgrender data=H1A1RRF_heat template=Heatmap2; 
dynamic _X='X' _Y='Y' _Z='Recurrence' _T="RRRI - H1A1";
TITLE "RPt";
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

What you need is the Range Attribute Map.  See the SAS documentation for GTL.  You can define the colors to be used for various data ranges, and then associate the range attr map (using range attr var) to the response variable of the Heat Map.

See http://blogs.sas.com/content/graphicallyspeaking/2013/04/14/attributes-map-3-range-attribute-map/.  The link at the bottom of the article will provide you the full code.

View solution in original post

4 REPLIES 4
Jay54
Meteorite | Level 14

What you need is the Range Attribute Map.  See the SAS documentation for GTL.  You can define the colors to be used for various data ranges, and then associate the range attr map (using range attr var) to the response variable of the Heat Map.

See http://blogs.sas.com/content/graphicallyspeaking/2013/04/14/attributes-map-3-range-attribute-map/.  The link at the bottom of the article will provide you the full code.

benbuck
Obsidian | Level 7

Thanks, I had seen this online, but wasn't sure if it worked for continuous variables, or just for discrete ones.

 

Thanks!

Ben

benbuck
Obsidian | Level 7

Got it! Thanks for your help!

 

In case it ever helps anyone, here is my updated code. 


proc template;
define statgraph Heatmap2;
dynamic _X _Y _Z _T;
begingraph;
dynamic _attr _title _x _y;
entrytitle _T;
entryfootnote halign=left 'H1A1 a';
rangeattrmap name='map';
range 0 -< 10 / rangecolormodel=(lightblue cxf7f7f7);
range 10 -< 15 / rangecolormodel=(cxf7f7f7 gold);
range 15 -< 20 / rangecolormodel=(gold red);
endrangeattrmap;
rangeattrvar attrvar=Recurrence var=Recurrence attrmap='map';
layout overlay / xaxisopts=(display=(ticks tickvalues))
yaxisopts=(display=(ticks tickvalues));;
if (exists(_attr))
heatmapparm x=_x y=_y colorresponse=Recurrence / name='a'; *colorresponse=attrvar kills it;
else
heatmapparm x=_x y=_y colorresponse=Recurrence / name='a';
continuouslegend 'a';
endif;
endlayout;
endgraph;
end;
run;

ODS GRAPHICS / width=5in height=4in IMAGENAME = 'Heatmap';
proc sgrender data=H1A1RRF_heat template=Heatmap2;
dynamic _X='X' _Y='Y' _Z='Recurrence' _T="Heatmap";
TITLE "Heatmap";
run;

 

Rick_SAS
SAS Super FREQ

I've written quite a few blog posts about heat maps.

There's one about how to create a basic heat map from GTL.

Search my blog for RANGEATTRMAP to see other examples.

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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