<?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: Set same range for heatmap on BY statement in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Set-same-range-for-heatmap-on-BY-statement/m-p/858620#M37917</link>
    <description>&lt;P&gt;Thank you Rick and Dan&lt;/P&gt;</description>
    <pubDate>Mon, 13 Feb 2023 21:10:48 GMT</pubDate>
    <dc:creator>linlin87</dc:creator>
    <dc:date>2023-02-13T21:10:48Z</dc:date>
    <item>
      <title>Set same range for heatmap on BY statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Set-same-range-for-heatmap-on-BY-statement/m-p/858490#M37912</link>
      <description>&lt;P&gt;Hi SAS community&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;I have heatmap of values (0-1). I have on a BY variable ("disease"). I want to do and I can't work out how:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Fix the color range to be 0-1. Currently it is using the minimum value in my dataset to be white, maximum to be black. I want white=0 and Black=1.&lt;/LI&gt;
&lt;LI&gt;Fix the color range across BY groups. Obviously with 1. above, when I do BY statement, it changes color map across the BY groups because it not fixed at 1 and 0.&lt;/LI&gt;
&lt;LI&gt;I want 'color legend' for all plots to display the full range: 0 (white) to 1 (black)&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Any help would be appreciate&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc template;
  define statgraph corrHeatmap;
   dynamic _Title;
    begingraph;
      entrytitle _Title;
      rangeattrmap name='map';
      endrangeattrmap;
      rangeattrvar var=r attrvar=r attrmap='map';
      layout overlay / 
        xaxisopts=(display=(line ticks tickvalues label) label=('Weeks wear')) 
        yaxisopts=(display=(line ticks tickvalues label) label=('Weeks wear'));
        heatmapparm x = x y = y colorresponse = rsquare / 
          xbinaxis=true ybinaxis=true
          name = "heatmap" display=all colormodel=(white black);
        continuouslegend "heatmap" / 
          orient = vertical location = outside title="Pearson Correlation";
      endlayout;
    endgraph;
  end;
run;

proc sort data=fit;
by disease;
run;
 
proc sgrender data=fit template=corrHeatmap;
	by disease;
	dynamic _title="Correlation matrix";
run;
 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 21:32:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Set-same-range-for-heatmap-on-BY-statement/m-p/858490#M37912</guid>
      <dc:creator>linlin87</dc:creator>
      <dc:date>2023-02-13T21:32:48Z</dc:date>
    </item>
    <item>
      <title>Re: Set same range for heatmap on BY statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Set-same-range-for-heatmap-on-BY-statement/m-p/858508#M37915</link>
      <description>&lt;P&gt;Two suggestions:&lt;BR /&gt;1. Use the RANGE statement inside the RANGEATTRMAP/ENDRANGEATTRMAP block.&lt;/P&gt;
&lt;P&gt;2. Add some fake data to each BY group to force the continuous legend to always display tick marks at 0 and 1. There might be a better way to do this. Maybe&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15130"&gt;@DanH_sas&lt;/a&gt;&amp;nbsp;knows a better way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc template;
  define statgraph corrHeatmap;
   dynamic _Title;
    begingraph;
      entrytitle _Title;
      rangeattrmap name='map';
      range 0-1;  /* set range to [0,1] */
      endrangeattrmap;
      rangeattrvar var=r attrvar=r attrmap='map';
      layout overlay / 
        xaxisopts=(display=(line ticks tickvalues label) label=('Weeks wear')) 
        yaxisopts=(display=(line ticks tickvalues label) label=('Weeks wear'));
        heatmapparm x = x y = y colorresponse = rsquare / 
          xbinaxis=true ybinaxis=true
          name = "heatmap" display=all colormodel=(white black);
        continuouslegend "heatmap" / 
          orient = vertical location = outside title="Pearson Correlation"
          VALUECOUNTHINT=11;
      endlayout;
    endgraph;
  end;
run;


/* make some example data */
data fit;
do disease = 1 to 2;
   do x = 0 to 3;
      do y = 0 to 3;
         rsquare = (disease + x**2 + y**2) / 25;   /* make range in [0, 1] */
         output;
      end;
   end;
end;
/* check that rsquare is in [0,1] */
proc means data=fit;
class disease;
var rsquare;
run;

proc sort data=fit;
by disease;
run;

/* HACK: insert fake data for rsquare=0 and  rsquare=1 to fool the continuous axis legend */
data Fake;
do disease = 1 to 2;    /* need fake obs for each value of disease */
   rsquare = -1E-3; output;
   rsquare =  1+ 1E-3; output;
end;
run;

data NewFit;
   set Fake Fit;
   by disease;
run;

proc sgrender data=NewFit template=corrHeatmap;
	by disease;
	dynamic _title="Correlation matrix";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Feb 2023 14:20:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Set-same-range-for-heatmap-on-BY-statement/m-p/858508#M37915</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2023-02-13T14:20:45Z</dc:date>
    </item>
    <item>
      <title>Re: Set same range for heatmap on BY statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Set-same-range-for-heatmap-on-BY-statement/m-p/858604#M37916</link>
      <description>&lt;P&gt;Using the RANGEATTRMAP is the best approach, but you're code needs a little adjustment:&lt;/P&gt;
&lt;P&gt;1. The COLORMODEL option needed to be removed from the HEATMAPPARM statement. Instead, the RANGECOLORMODEL needs to be defined on the RANGE statement. Otherwise, there is no binding between the 0-1 range and the white-black color range&lt;/P&gt;
&lt;P&gt;2. The RANGEATTRVAR needs to have the RSQUARE variable specified on the VAR option. This option points to the real column in the data. The ATTRVAR option specifies a new reference variable name. This variable (not the RSQUARE) should be used for the COLORRESPONSE on the HEATMAPPARM to create the correct binding.&lt;/P&gt;
&lt;P&gt;3. The fake data is not required, so I removed it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc template;
  define statgraph corrHeatmap;
   dynamic _Title;
    begingraph;
      entrytitle _Title;
      rangeattrmap name='map';
      range 0.0-1.0 / rangecolormodel=(white black);
      endrangeattrmap;
      rangeattrvar var=rsquare attrvar=r attrmap="map";
      layout overlay /
        xaxisopts=(display=(line ticks tickvalues label) label=('Weeks wear'))
        yaxisopts=(display=(line ticks tickvalues label) label=('Weeks wear'));
        heatmapparm x = x y = y colorresponse = r /
          xbinaxis=true ybinaxis=true
          name = "heatmap" display=all ;
        continuouslegend "heatmap" /
          orient = vertical location = outside title="Pearson Correlation"
          VALUECOUNTHINT=11;
      endlayout;
    endgraph;
  end;
run;

/* make some example data */
data fit;
do disease = 1 to 2;
   do x = 0 to 3;
      do y = 0 to 3;
         rsquare = (disease + x**2 + y**2) / 25;   /* make range in [0, 1] */
         output;
      end;
   end;
end;
/* check that rsquare is in [0,1] */
proc means data=fit;
class disease;
var rsquare;
run;

proc sort data=fit;
by disease;
run;

proc sgrender data=fit template=corrHeatmap;
	by disease;
	dynamic _title="Correlation matrix";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Feb 2023 20:14:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Set-same-range-for-heatmap-on-BY-statement/m-p/858604#M37916</guid>
      <dc:creator>DanH_sas</dc:creator>
      <dc:date>2023-02-13T20:14:59Z</dc:date>
    </item>
    <item>
      <title>Re: Set same range for heatmap on BY statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Set-same-range-for-heatmap-on-BY-statement/m-p/858620#M37917</link>
      <description>&lt;P&gt;Thank you Rick and Dan&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 21:10:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Set-same-range-for-heatmap-on-BY-statement/m-p/858620#M37917</guid>
      <dc:creator>linlin87</dc:creator>
      <dc:date>2023-02-13T21:10:48Z</dc:date>
    </item>
  </channel>
</rss>

