<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: show cell values in heat map of a correlation matrix in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/show-cell-values-in-heat-map-of-a-correlation-matrix/m-p/776258#M246831</link>
    <description>Here's a different way, but it controls the colour shading levels a bit more but overall and the code is simpler using SGPLOT instead.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://gist.github.com/statgeek/566dda98173a5a28a6e4147317547959" target="_blank"&gt;https://gist.github.com/statgeek/566dda98173a5a28a6e4147317547959&lt;/A&gt;</description>
    <pubDate>Mon, 25 Oct 2021 17:44:26 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-10-25T17:44:26Z</dc:date>
    <item>
      <title>show cell values in heat map of a correlation matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/show-cell-values-in-heat-map-of-a-correlation-matrix/m-p/776251#M246830</link>
      <description>&lt;P&gt;this code came from Chris Hemedinger's blog:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sasdummy/2013/06/12/correlations-matrix-heatmap-with-sas/" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2013/06/12/correlations-matrix-heatmap-with-sas/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;I want to include the correlation coefficient in each cell of the heat map. If I hover over the output I see the value of r&amp;nbsp; but I cannot output it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Prepare the correlations coeff matrix: Pearson's r method */
%macro prepCorrData(in=,out=);
  /* Run corr matrix for input data, all numeric vars */
  proc corr data=&amp;amp;in. noprint
    pearson
    outp=work._tmpCorr
    vardef=df
  ;
  run;
 
  /* prep data for heat map */
data &amp;amp;out.;
  keep x y r;
  set work._tmpCorr(where=(_TYPE_="CORR"));
  array v{*} _numeric_;
  x = _NAME_;
  do i = dim(v) to 1 by -1;
    y = vname(v(i));
    r = v(i);
    /* creates a lower triangular matrix */
    if (i&amp;lt;_n_) then
      r=.;
    output;
  end;
run;
 
proc datasets lib=work nolist nowarn;
  delete _tmpcorr;
quit;
%mend;

  /* Create a heat map implementation of a correlation matrix */
ods path work.mystore(update) sashelp.tmplmst(read);
 
proc template;
  define statgraph corrHeatmap;
   dynamic _Title;
    begingraph;
      entrytitle _Title;
      rangeattrmap name='map';
      /* select a series of colors that represent a "diverging"  */
      /* range of values: stronger on the ends, weaker in middle */
      /* Get ideas from http://colorbrewer.org                   */
      range -1 - 1 / rangecolormodel=(cxD8B365 cxF5F5F5 cx5AB4AC);
      endrangeattrmap;
      rangeattrvar var=r attrvar=r attrmap='map';
      layout overlay / 
        xaxisopts=(display=(line ticks tickvalues)) 
        yaxisopts=(display=(line ticks tickvalues));
        heatmapparm x = x y = y colorresponse = r / 
          xbinaxis=false ybinaxis=false
          name = "heatmap" display=all;
        continuouslegend "heatmap" / 
          orient = vertical location = outside title="Pearson Correlation";
      endlayout;
    endgraph;
  end;
run;

/* Build the graphs */
ods graphics /height=600 width=800 imagemap;
 
%prepCorrData(in=sashelp.cars,out=cars_r);
proc sgrender data=cars_r template=corrHeatmap;
   dynamic _title="Corr matrix for SASHELP.cars";
run;
 
%prepCorrData(in=sashelp.iris,out=iris_r);
proc sgrender data=iris_r template=corrHeatmap;
   dynamic _title= "Corr matrix for SASHELP.iris";
run;
 
/* example of dropping categorical numerics */
%prepCorrData(
  in=sashelp.pricedata(drop=region date product line),
  out=pricedata_r);
proc sgrender data=pricedata_r template=corrHeatmap;
  dynamic _title="Corr matrix for SASHELP.pricedata";
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="GreggB_0-1635182993745.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65009iEC03D915977BD9B7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="GreggB_0-1635182993745.png" alt="GreggB_0-1635182993745.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Oct 2021 17:30:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/show-cell-values-in-heat-map-of-a-correlation-matrix/m-p/776251#M246830</guid>
      <dc:creator>GreggB</dc:creator>
      <dc:date>2021-10-25T17:30:09Z</dc:date>
    </item>
    <item>
      <title>Re: show cell values in heat map of a correlation matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/show-cell-values-in-heat-map-of-a-correlation-matrix/m-p/776258#M246831</link>
      <description>Here's a different way, but it controls the colour shading levels a bit more but overall and the code is simpler using SGPLOT instead.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://gist.github.com/statgeek/566dda98173a5a28a6e4147317547959" target="_blank"&gt;https://gist.github.com/statgeek/566dda98173a5a28a6e4147317547959&lt;/A&gt;</description>
      <pubDate>Mon, 25 Oct 2021 17:44:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/show-cell-values-in-heat-map-of-a-correlation-matrix/m-p/776258#M246831</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-25T17:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: show cell values in heat map of a correlation matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/show-cell-values-in-heat-map-of-a-correlation-matrix/m-p/776266#M246833</link>
      <description>&lt;P&gt;Do you know how to control the overall size of the matrix?&amp;nbsp; This is my output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="GreggB_0-1635186375603.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65012i85B8144598468941/image-size/medium?v=v2&amp;amp;px=400" role="button" title="GreggB_0-1635186375603.png" alt="GreggB_0-1635186375603.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Oct 2021 18:26:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/show-cell-values-in-heat-map-of-a-correlation-matrix/m-p/776266#M246833</guid>
      <dc:creator>GreggB</dc:creator>
      <dc:date>2021-10-25T18:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: show cell values in heat map of a correlation matrix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/show-cell-values-in-heat-map-of-a-correlation-matrix/m-p/776273#M246838</link>
      <description>Since it's SGPLOT you can use the standard ODS GRAPHICS options to control the size of the graph. &lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://documentation.sas.com/doc/en/vdmmlcdc/8.1/grstatproc/n0yadqm4wsfapgn1hzekfvu1ex0g.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/vdmmlcdc/8.1/grstatproc/n0yadqm4wsfapgn1hzekfvu1ex0g.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;ods graphics on / width=4.5in height=3.5in;</description>
      <pubDate>Mon, 25 Oct 2021 18:59:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/show-cell-values-in-heat-map-of-a-correlation-matrix/m-p/776273#M246838</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-25T18:59:01Z</dc:date>
    </item>
  </channel>
</rss>

