Data visualization with SAS programming

How do i create a Heat Map with Proc Template

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

How do i create a Heat Map with Proc Template

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;

Accepted Solutions
Solution
‎02-02-2016 10:38 PM
SAS Super FREQ
Posts: 1,044

Re: How do i create a Heat Map with Proc Template

[ Edited ]

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


All Replies
Solution
‎02-02-2016 10:38 PM
SAS Super FREQ
Posts: 1,044

Re: How do i create a Heat Map with Proc Template

[ Edited ]

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.

Occasional Contributor
Posts: 12

Re: How do i create a Heat Map with Proc Template

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

 

Thanks!

Ben

Occasional Contributor
Posts: 12

Re: How do i create a Heat Map with Proc Template

[ Edited ]

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;

 

SAS Super FREQ
Posts: 3,238

Re: How do i create a Heat Map with Proc Template

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.

 

 

Post a Question
Discussion Stats
  • 4 replies
  • 492 views
  • 0 likes
  • 3 in conversation