<?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 Color coding columns in proc report in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Color-coding-columns-in-proc-report/m-p/873980#M345265</link>
    <description>&lt;P&gt;I searched this group on the topic and tried applying the solutions to my table, but it doesn't work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dummy dataset (temp1) with 4 columns, label, value1, value2, value3 (note that value3 is dummy data and will be different than value2 in the actual data)&lt;/P&gt;
&lt;P&gt;I want to color code column Value1 red if it's less than Value2 and green if it's more than Value2.&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="373"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="106"&gt;Label&lt;/TD&gt;
&lt;TD width="89"&gt;Value1&lt;/TD&gt;
&lt;TD width="89"&gt;Value2&lt;/TD&gt;
&lt;TD width="89"&gt;Value3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Sales&lt;/TD&gt;
&lt;TD&gt;2725865.52&lt;/TD&gt;
&lt;TD&gt;4167644.47&lt;/TD&gt;
&lt;TD&gt;4167644.47&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Profit&lt;/TD&gt;
&lt;TD&gt;3.987452276&lt;/TD&gt;
&lt;TD&gt;6.563600013&lt;/TD&gt;
&lt;TD&gt;6.563600013&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Income&lt;/TD&gt;
&lt;TD&gt;-8.012547724&lt;/TD&gt;
&lt;TD&gt;-5.436399987&lt;/TD&gt;
&lt;TD&gt;-5.436399987&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;% Profit&lt;/TD&gt;
&lt;TD&gt;0.054198967&lt;/TD&gt;
&lt;TD&gt;0.091224184&lt;/TD&gt;
&lt;TD&gt;0.091224184&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;% Expense&lt;/TD&gt;
&lt;TD&gt;0.16310856&lt;/TD&gt;
&lt;TD&gt;0.166781981&lt;/TD&gt;
&lt;TD&gt;0.166781981&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Average Sales&lt;/TD&gt;
&lt;TD&gt;73.57063291&lt;/TD&gt;
&lt;TD&gt;71.95021874&lt;/TD&gt;
&lt;TD&gt;71.95021874&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried the following Proc Report but the entire Column Value 1 turns green. I am not sure why that's happening. Any solutions?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc report nowd data=temp1&lt;/P&gt;
&lt;P&gt;STYLE(header) = HEADER{background=lightBlue fontsize=2}&lt;BR /&gt;STYLE(Report) = {frame=box bordercolor = grey borderwidth=2px};&lt;/P&gt;
&lt;P&gt;column Label value1 value2 value3;&lt;BR /&gt;&lt;BR /&gt;define LABEL/ " " missing;&lt;BR /&gt;define value1 / display 'Value 1' STYLE(COLUMN)=[JUST=l] format=DOLLAR20. missing;&lt;BR /&gt;define value2 /display 'Value 2' STYLE(COLUMN)=[JUST=l] format=DOLLAR20. missing;&lt;BR /&gt;define value3 /display 'Value 3' STYLE(COLUMN)=[JUST=l] format=DOLLAR20. missing;&lt;/P&gt;
&lt;P&gt;compute Label;&lt;BR /&gt;&lt;BR /&gt;call define (_col_, "style", "STYLE=[BACKGROUND=MISTYROSE]");&lt;/P&gt;
&lt;P&gt;endcomp;&lt;/P&gt;
&lt;P&gt;compute value1;&lt;/P&gt;
&lt;P&gt;if (label = "% Profit") then do;&lt;BR /&gt;call define (_col_, 'format', 'percent9.1');&lt;BR /&gt;end;&lt;BR /&gt;if (label = "% Expense") then do;&lt;BR /&gt;call define (_col_, 'format', 'percent9.1');&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;if value1 &amp;gt;= value2 THEN CALL DEFINE(_col_, "STYLE", "STYLE={BACKGROUND=green}");&lt;BR /&gt;if value1 &amp;lt; value2 THEN CALL DEFINE(_col_, "STYLE", "STYLE={BACKGROUND=red}");&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;endcomp;&lt;/P&gt;
&lt;P&gt;compute value2;&lt;BR /&gt;if (label = "% Profit") then do;&lt;BR /&gt;call define (_col_, 'format', 'percent9.1');&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;if (label = "% Expense") then do;&lt;BR /&gt;call define (_col_, 'format', 'percent9.1');&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;call define (_col_, "style", "STYLE=[BACKGROUND=LIGHTYELLOW]");&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;endcomp;&lt;/P&gt;
&lt;P&gt;compute value3;&lt;BR /&gt;if (label = "% Profit") then do;&lt;BR /&gt;call define (_col_, 'format', 'percent9.1');&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;if (label = "% Expense") then do;&lt;BR /&gt;call define (_col_, 'format', 'percent9.1');&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;call define (_col_, "style", "STYLE=[BACKGROUND=LIGHTGREY]");&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;endcomp;&lt;/P&gt;
&lt;P&gt;RUN; &lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 04 May 2023 19:06:28 GMT</pubDate>
    <dc:creator>monali</dc:creator>
    <dc:date>2023-05-04T19:06:28Z</dc:date>
    <item>
      <title>Color coding columns in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Color-coding-columns-in-proc-report/m-p/873980#M345265</link>
      <description>&lt;P&gt;I searched this group on the topic and tried applying the solutions to my table, but it doesn't work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dummy dataset (temp1) with 4 columns, label, value1, value2, value3 (note that value3 is dummy data and will be different than value2 in the actual data)&lt;/P&gt;
&lt;P&gt;I want to color code column Value1 red if it's less than Value2 and green if it's more than Value2.&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="373"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="106"&gt;Label&lt;/TD&gt;
&lt;TD width="89"&gt;Value1&lt;/TD&gt;
&lt;TD width="89"&gt;Value2&lt;/TD&gt;
&lt;TD width="89"&gt;Value3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Sales&lt;/TD&gt;
&lt;TD&gt;2725865.52&lt;/TD&gt;
&lt;TD&gt;4167644.47&lt;/TD&gt;
&lt;TD&gt;4167644.47&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Profit&lt;/TD&gt;
&lt;TD&gt;3.987452276&lt;/TD&gt;
&lt;TD&gt;6.563600013&lt;/TD&gt;
&lt;TD&gt;6.563600013&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Income&lt;/TD&gt;
&lt;TD&gt;-8.012547724&lt;/TD&gt;
&lt;TD&gt;-5.436399987&lt;/TD&gt;
&lt;TD&gt;-5.436399987&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;% Profit&lt;/TD&gt;
&lt;TD&gt;0.054198967&lt;/TD&gt;
&lt;TD&gt;0.091224184&lt;/TD&gt;
&lt;TD&gt;0.091224184&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;% Expense&lt;/TD&gt;
&lt;TD&gt;0.16310856&lt;/TD&gt;
&lt;TD&gt;0.166781981&lt;/TD&gt;
&lt;TD&gt;0.166781981&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Average Sales&lt;/TD&gt;
&lt;TD&gt;73.57063291&lt;/TD&gt;
&lt;TD&gt;71.95021874&lt;/TD&gt;
&lt;TD&gt;71.95021874&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried the following Proc Report but the entire Column Value 1 turns green. I am not sure why that's happening. Any solutions?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc report nowd data=temp1&lt;/P&gt;
&lt;P&gt;STYLE(header) = HEADER{background=lightBlue fontsize=2}&lt;BR /&gt;STYLE(Report) = {frame=box bordercolor = grey borderwidth=2px};&lt;/P&gt;
&lt;P&gt;column Label value1 value2 value3;&lt;BR /&gt;&lt;BR /&gt;define LABEL/ " " missing;&lt;BR /&gt;define value1 / display 'Value 1' STYLE(COLUMN)=[JUST=l] format=DOLLAR20. missing;&lt;BR /&gt;define value2 /display 'Value 2' STYLE(COLUMN)=[JUST=l] format=DOLLAR20. missing;&lt;BR /&gt;define value3 /display 'Value 3' STYLE(COLUMN)=[JUST=l] format=DOLLAR20. missing;&lt;/P&gt;
&lt;P&gt;compute Label;&lt;BR /&gt;&lt;BR /&gt;call define (_col_, "style", "STYLE=[BACKGROUND=MISTYROSE]");&lt;/P&gt;
&lt;P&gt;endcomp;&lt;/P&gt;
&lt;P&gt;compute value1;&lt;/P&gt;
&lt;P&gt;if (label = "% Profit") then do;&lt;BR /&gt;call define (_col_, 'format', 'percent9.1');&lt;BR /&gt;end;&lt;BR /&gt;if (label = "% Expense") then do;&lt;BR /&gt;call define (_col_, 'format', 'percent9.1');&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;if value1 &amp;gt;= value2 THEN CALL DEFINE(_col_, "STYLE", "STYLE={BACKGROUND=green}");&lt;BR /&gt;if value1 &amp;lt; value2 THEN CALL DEFINE(_col_, "STYLE", "STYLE={BACKGROUND=red}");&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;endcomp;&lt;/P&gt;
&lt;P&gt;compute value2;&lt;BR /&gt;if (label = "% Profit") then do;&lt;BR /&gt;call define (_col_, 'format', 'percent9.1');&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;if (label = "% Expense") then do;&lt;BR /&gt;call define (_col_, 'format', 'percent9.1');&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;call define (_col_, "style", "STYLE=[BACKGROUND=LIGHTYELLOW]");&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;endcomp;&lt;/P&gt;
&lt;P&gt;compute value3;&lt;BR /&gt;if (label = "% Profit") then do;&lt;BR /&gt;call define (_col_, 'format', 'percent9.1');&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;if (label = "% Expense") then do;&lt;BR /&gt;call define (_col_, 'format', 'percent9.1');&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;call define (_col_, "style", "STYLE=[BACKGROUND=LIGHTGREY]");&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;endcomp;&lt;/P&gt;
&lt;P&gt;RUN; &lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2023 19:06:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Color-coding-columns-in-proc-report/m-p/873980#M345265</guid>
      <dc:creator>monali</dc:creator>
      <dc:date>2023-05-04T19:06:28Z</dc:date>
    </item>
    <item>
      <title>Re: Color coding columns in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Color-coding-columns-in-proc-report/m-p/873983#M345266</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;compute value1;
    if (label = "% Profit") then do;
        call define (_col_, 'format', 'percent9.1');
    end;
    if (label = "% Expense") then do;
        call define (_col_, 'format', 'percent9.1');
    end;
    if value1 &amp;gt;= value2 THEN CALL DEFINE(_col_, "STYLE", "STYLE={BACKGROUND=green}");
    if value1 &amp;lt; value2 THEN CALL DEFINE(_col_, "STYLE", "STYLE={BACKGROUND=red}");
endcomp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;Code should always be presented in a code box (use the "little running man" icon) and properly indented.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The error happens because you cannot refer to value2 in the COMPUTE block for value1. The way SAS designed PROC REPORT, you can only refer to columns to the left of the current column, and value2 is to the right of the current column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A possible solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report nowd data=temp1
    STYLE(header) = HEADER{background=lightBlue fontsize=2}
    STYLE(Report) = {frame=box bordercolor = grey borderwidth=2px};
    column Label value2 value1 value2a=value2 value3;
    define LABEL/ " " missing;
    define value2 / noprint display;
    define value1 / display 'Value 1' STYLE(COLUMN)=[JUST=l] format=DOLLAR20. missing;
    define value2a /display 'Value 2' STYLE(COLUMN)=[JUST=l] format=DOLLAR20. missing;
    define value3 /display 'Value 3' STYLE(COLUMN)=[JUST=l] format=DOLLAR20. missing;
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This should now allow you to use value2 in a formula in the compute block for value1 (because now value2 is to the left of value1), and value2a as the next column. This is untested, as I don't have your data. Data should be provided as working SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;examples and instructions&lt;/A&gt;).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2023 19:26:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Color-coding-columns-in-proc-report/m-p/873983#M345266</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-05-04T19:26:10Z</dc:date>
    </item>
    <item>
      <title>Re: Color coding columns in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Color-coding-columns-in-proc-report/m-p/873997#M345270</link>
      <description>&lt;P&gt;possible option would be creating flag variables and "style/replace"&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp2;
infile cards4 dlm="|";
input Label : $ 20. Value1  Value2  Value3;
flag1=value1 &amp;gt;= value2;
flag2=not flag1;
cards4;
Sales|2725865.52|4167644.47|4167644.47
Profit|3.987452276|6.563600013|6.563600013
Income|-8.012547724|-5.436399987|-5.436399987
% Profit|0.154198967|0.091224184|0.091224184
% Expense|0.16310856|0.166781981|0.166781981
Average Sales|73.57063291|71.95021874|71.95021874
;;;;
run;

proc report nowd data=temp2

STYLE(header) = HEADER{background=lightBlue fontsize=2}
STYLE(Report) = {frame=box bordercolor = grey borderwidth=2px};

column Label value1 value2 value3 flag1 flag2;

define LABEL/ " " missing;
define value1 / display 'Value 1' STYLE(COLUMN)=[JUST=l] format=DOLLAR20. missing;
define value2 / display 'Value 2' STYLE(COLUMN)=[JUST=l] format=DOLLAR20. missing;
define value3 / display 'Value 3' STYLE(COLUMN)=[JUST=l] format=DOLLAR20. missing;
define flag1 /  NOPRINT display missing;
define flag2 /  NOPRINT display missing;

compute Label;
call define (_col_, "style", "STYLE=[BACKGROUND=MISTYROSE]");
endcomp;

compute Value1;
if (label = "% Profit") then do;
call define (_col_, 'format', 'percent9.1');
end;
if (label = "% Expense") then do;
call define (_col_, 'format', 'percent9.1');
end;
endcomp;

compute value2;
if (label = "% Profit") then do;
call define (_col_, 'format', 'percent9.1');
end;
if (label = "% Expense") then do;
call define (_col_, 'format', 'percent9.1');
end;
call define (_col_, "style", "STYLE=[BACKGROUND=LIGHTYELLOW]");
endcomp;

compute value3;
if (label = "% Profit") then do;
call define (_col_, 'format', 'percent9.1');
end;
if (label = "% Expense") then do;
call define (_col_, 'format', 'percent9.1');
end;
call define (_col_, "style", "STYLE=[BACKGROUND=LIGHTGREY]");
endcomp;


compute flag1;
 if (flag1 = 1) then
    call define('value1', "style", "style=[background=green]");
    else call define('value1', "style", "style=[background=red]");
endcomp;

compute flag2;
 if (flag2 = 1) then
        call define('value1', "style/replace", "style=[background=red]");
        else call define('value1', "style/replace", "style=[background=green]");
endcomp;


RUN;
quit;
 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;it produces:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="yabwon_0-1683231386473.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83634iB6172D33F18F3C86/image-size/medium?v=v2&amp;amp;px=400" role="button" title="yabwon_0-1683231386473.png" alt="yabwon_0-1683231386473.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;based on:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p0934x0xj13fm9n1l164y36xttk1.htm" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p0934x0xj13fm9n1l164y36xttk1.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2023 20:17:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Color-coding-columns-in-proc-report/m-p/873997#M345270</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-05-04T20:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: Color coding columns in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Color-coding-columns-in-proc-report/m-p/873999#M345271</link>
      <description>&lt;P&gt;Both solutions worked!! Thank you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2023 20:32:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Color-coding-columns-in-proc-report/m-p/873999#M345271</guid>
      <dc:creator>monali</dc:creator>
      <dc:date>2023-05-04T20:32:35Z</dc:date>
    </item>
  </channel>
</rss>

