<?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: Color a table cell using PROC REPORT, using a numeric variable that is different from cell varia in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Color-a-table-cell-using-PROC-REPORT-using-a-numeric-variable/m-p/744538#M25052</link>
    <description>&lt;P&gt;Here's one way: change the column order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc report data=test nowindows headline headskip;
columns c a b  ;
define a / display ' Level ' width =6;
define b / display ' Home ' width =6;
define c / display ' color' width = 6;
compute b;
if b &amp;gt; 3 then call define(_col_,"style","style={background = red");
endcompute;
compute a;
  if c &amp;gt; 4 then call define(_col_,"style","style={background = green");
endcompute;
run;&lt;/PRE&gt;
&lt;P&gt;Why do this? Proc Report builds the report from left to right. So while construction the column for A, when the column statement is A B C, the value of C (to the Right of A) is not "available" yet.&lt;/P&gt;
&lt;P&gt;Same problem with the _cn_ approach, column 3 not available for A (_c1_)&lt;/P&gt;
&lt;P&gt;I&lt;/P&gt;</description>
    <pubDate>Fri, 28 May 2021 19:57:41 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-05-28T19:57:41Z</dc:date>
    <item>
      <title>Color a table cell using PROC REPORT, using a numeric variable that is different from cell variable</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Color-a-table-cell-using-PROC-REPORT-using-a-numeric-variable/m-p/744532#M25050</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to color a cell of a table using PROC REPORT, but using a variable that is different from the variable that is in the cell.&amp;nbsp; The problem is reproduceable from this following simple program, and described in greater detail following the simple program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sample program:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input a b c;
cards;
1 2 3
1 2 4
1 2 4
2 4 5
2 4 1
2 4 6
;

proc print;
var a b c;
run;


proc report data=test nowindows headline headskip;
columns a b c ;
define a / display ' Level ' width =6;
define b / display ' Home ' width =6;
define c / display ' color' width = 6;
compute b;
if b &amp;gt; 3 then call define(_col_,"style","style={background = red");
endcompute;
*compute a;
* if c &amp;gt; 4 then call define(_col_,"style","style={background = green");
* endcompute;
compute a;
if _c3_ &amp;gt; 4 then call define(_col_,"style","style={background = green");
endcompute;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the above program, the first compute statement colors the Home column cells red for those cells where the Home column is greater than 3.&amp;nbsp; This works fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I would really like to color the cells of Level green, based on the values of the color column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second compute statement (that is commented out) does the obvious, which does not work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The third compute statement uses the _Cn_ approach to identifying the column to create the color values. No error or warnings are produced, but the colored cells do not appear on the table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The resulting table should have two cells in the Level column colored green.&amp;nbsp; The 4th and 6th cell.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the reason wanting to do this is not clear from&amp;nbsp; the test data, but makes sense in the table I am creating.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any thoughts from would be greatly appreciated. (Note I could not find anything on this in my searching of the archives).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sincerely,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dan&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 May 2021 19:46:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Color-a-table-cell-using-PROC-REPORT-using-a-numeric-variable/m-p/744532#M25050</guid>
      <dc:creator>Dan16</dc:creator>
      <dc:date>2021-05-28T19:46:14Z</dc:date>
    </item>
    <item>
      <title>Re: Color a table cell using PROC REPORT, using a numeric variable that is different from cell varia</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Color-a-table-cell-using-PROC-REPORT-using-a-numeric-variable/m-p/744534#M25051</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=test nowindows headline headskip;
columns a b c ;
define a / display ' Level ' width =6;
define b / display ' Home ' width =6;
define c / display ' color' width = 6;

compute c;
 if c &amp;gt; 4 then call define(a,"style","style={background = green");
 endcompute;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 May 2021 19:50:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Color-a-table-cell-using-PROC-REPORT-using-a-numeric-variable/m-p/744534#M25051</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-05-28T19:50:04Z</dc:date>
    </item>
    <item>
      <title>Re: Color a table cell using PROC REPORT, using a numeric variable that is different from cell varia</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Color-a-table-cell-using-PROC-REPORT-using-a-numeric-variable/m-p/744538#M25052</link>
      <description>&lt;P&gt;Here's one way: change the column order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc report data=test nowindows headline headskip;
columns c a b  ;
define a / display ' Level ' width =6;
define b / display ' Home ' width =6;
define c / display ' color' width = 6;
compute b;
if b &amp;gt; 3 then call define(_col_,"style","style={background = red");
endcompute;
compute a;
  if c &amp;gt; 4 then call define(_col_,"style","style={background = green");
endcompute;
run;&lt;/PRE&gt;
&lt;P&gt;Why do this? Proc Report builds the report from left to right. So while construction the column for A, when the column statement is A B C, the value of C (to the Right of A) is not "available" yet.&lt;/P&gt;
&lt;P&gt;Same problem with the _cn_ approach, column 3 not available for A (_c1_)&lt;/P&gt;
&lt;P&gt;I&lt;/P&gt;</description>
      <pubDate>Fri, 28 May 2021 19:57:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Color-a-table-cell-using-PROC-REPORT-using-a-numeric-variable/m-p/744538#M25052</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-28T19:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: Color a table cell using PROC REPORT, using a numeric variable that is different from cell varia</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Color-a-table-cell-using-PROC-REPORT-using-a-numeric-variable/m-p/744549#M25053</link>
      <description>&lt;P&gt;There's actually no need to change the column order.&amp;nbsp; The variable you put in the compute block is rather arbitrary to what is in the compute block, so the easiest way to do this is to always put the last variable in the COLUMNS statement in the compute statement.&amp;nbsp; This way all the variables are always initialized and you can do whatever style changes are needed (even if they are on a different column than the one in the compute statement and even if there are multiple changes).&amp;nbsp; I think &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; was touching on this in their post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=test nowindows headline headskip;
columns a b c;
define a / display ' Level ' width =6;
define b / display ' Home ' width =6;
define c / display ' color' width = 6;
compute c;
if b &amp;gt; 3 then call define('b',"style","style={background = red");
if c &amp;gt; 4 then call define('a',"style","style={background = green");
endcompute;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 May 2021 21:51:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Color-a-table-cell-using-PROC-REPORT-using-a-numeric-variable/m-p/744549#M25053</guid>
      <dc:creator>JeffMeyers</dc:creator>
      <dc:date>2021-05-28T21:51:04Z</dc:date>
    </item>
    <item>
      <title>Re: Color a table cell using PROC REPORT, using a numeric variable that is different from cell varia</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Color-a-table-cell-using-PROC-REPORT-using-a-numeric-variable/m-p/744631#M25054</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Thanks for posting data. Using your test data and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;'s suggestion:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1622322155108.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59884i3B9EB7167976C249/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1622322155108.png" alt="Cynthia_sas_0-1622322155108.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;As you can see, I get the correct color coding in columns A and B as you intended with your original code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I explain in the screen shot that the COMPUTE block for A cannot test the value of C because of the PROC REPORT "left-to-right" rule and a timing issue. At the point in time when PROC REPORT is placing A on the report row, it has not yet placed C on the report row. So the COMPUTE block for A cannot test the value of C. However, you can test the value for C in the COMPUTE block for C. At that point in time, the cell for column A has been placed on the report row, so based on the result of the IF in the COMPUTE block a CALL DEFINE in the COMPUTE block for C can "touch" a variable that appears before C in the COLUMN statement. The only trick is that the variable name you want to change with the call define must be quoted, as I show in my code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Just a few other comments. HEADLINE, HEADSKIP and WIDTH= are ignored by ODS destinations that would use your STYLE. These are LISTING only options and ignored by ODS, so I removed them from my code. I also changed the colors to lightgreen and lightred to make the numbers in the cells more readable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Hope this helps,&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Sat, 29 May 2021 21:06:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Color-a-table-cell-using-PROC-REPORT-using-a-numeric-variable/m-p/744631#M25054</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2021-05-29T21:06:59Z</dc:date>
    </item>
  </channel>
</rss>

