<?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: proc report-color cells in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-report-color-cells/m-p/694223#M211705</link>
    <description>&lt;P&gt;Don't make us guess. What is wrong with the macro solution you provided?&lt;/P&gt;</description>
    <pubDate>Mon, 26 Oct 2020 12:29:56 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-10-26T12:29:56Z</dc:date>
    <item>
      <title>proc report-color cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-report-color-cells/m-p/694221#M211704</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to color values if the exceed UCL1 or UCL2 (As you can see in the code).&lt;/P&gt;
&lt;P&gt;My question:&lt;/P&gt;
&lt;P&gt;What is the way to write one&amp;nbsp;compute statements for multiple&amp;nbsp; columns?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data RedLights;
Input Subject UCL1 UCL2 Val2009 Val2006 Val2003 Val1912;
cards;
1 15 20 10 8 9 18
2 13 14 15 10 9 8
3 70 80 50 45 90 30
4 25 35 30 16 15 12
5 30 40 17 20 25 30
;
run;


proc report data=RedLights nowd;
column Subject UCL1 UCL2 Val2009 Val2006 Val2003 Val1912;
define Subject / display  'Subjecy Numner';
define UCL1 / display  "Upper Control Limit1";
define UCL2 / display  "Upper Control Limit2";
define Val2009 / display 'Sep-2020';
define Val2006 / display 'JUN-2020';
define Val2003 / display 'MAR-2020';
define Val1912 / display 'DEC-2019';
compute Val2009;
if Val2009&amp;gt;UCL1 and Val2009&amp;gt;UCL2 then call define(_col_,"style","style={background=red}");
else if Val2009&amp;gt;UCL1 and Val2009&amp;lt;=UCL2 then call define(_col_,"style","style={background=lightpink}");
else if Val2009&amp;lt;=UCL1 and Val2009&amp;gt;UCL2 then call define(_col_,"style","style={background=pink}");
else call define(_col_,"style","style={background=lightgreen}");
endcomp;

compute Val2006;
if Val2006&amp;gt;UCL1 and Val2006&amp;gt;UCL2 then call define(_col_,"style","style={background=red}");
else if Val2006&amp;gt;UCL1 and Val2006&amp;lt;=UCL2 then call define(_col_,"style","style={background=lightpink}");
else if Val2006&amp;lt;=UCL1 and Val2006&amp;gt;UCL2 then call define(_col_,"style","style={background=pink}");
else call define(_col_,"style","style={background=lightgreen}");
endcomp;

compute Val2003;
if Val2003&amp;gt;UCL1 and Val2003&amp;gt;UCL2 then call define(_col_,"style","style={background=red}");
else if Val2003&amp;gt;UCL1 and Val2003&amp;lt;=UCL2 then call define(_col_,"style","style={background=lightpink}");
else if Val2003&amp;lt;=UCL1 and Val2003&amp;gt;UCL2 then call define(_col_,"style","style={background=pink}");
else call define(_col_,"style","style={background=lightgreen}");
endcomp;

compute Val1912;
if Val1912&amp;gt;UCL1 and Val1912&amp;gt;UCL2 then call define(_col_,"style","style={background=red}");
else if Val1912&amp;gt;UCL1 and Val1912&amp;lt;=UCL2 then call define(_col_,"style","style={background=lightpink}");
else if Val1912&amp;lt;=UCL1 and Val1912&amp;gt;UCL2 then call define(_col_,"style","style={background=pink}");
else call define(_col_,"style","style={background=lightgreen}");
endcomp;
run;

/***My try to do it****/
/***My try to do it****/
/***My try to do it****/
%let vector =Val2009+Val2006+Val2003+Val1912;
%let k=4;

%macro mmacro1; 
%do j=1 %to &amp;amp;k.;
%let Val=%scan(&amp;amp;vector1.,&amp;amp;j.,+);
compute &amp;amp;val.;
if &amp;amp;val.&amp;gt;UCL1 and &amp;amp;val.&amp;gt;UCL2 then call define(_col_,"style","style={background=red}");
else if &amp;amp;val.&amp;gt;UCL1 and &amp;amp;val.&amp;lt;=UCL2 then call define(_col_,"style","style={background=lightpink}");
else if &amp;amp;val.&amp;lt;=UCL1 and &amp;amp;val.&amp;gt;UCL2 then call define(_col_,"style","style={background=pink}");
else call define(_col_,"style","style={background=lightgreen}");
endcomp;
%end;
%mend mmacro1;


proc report data=RedLights nowd;
column Subject UCL1 UCL2 Val2009 Val2006 Val2003 Val1912;
define Subject / display  'Subjecy Numner';
define UCL1 / display  "Upper Control Limit1";
define UCL2 / display  "Upper Control Limit2";
define Val2009 / display 'Sep-2020';
define Val2006 / display 'JUN-2020';
define Val2003 / display 'MAR-2020';
define Val1912 / display 'DEC-2019';
%mmacro1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Oct 2020 12:21:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-report-color-cells/m-p/694221#M211704</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-10-26T12:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: proc report-color cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-report-color-cells/m-p/694223#M211705</link>
      <description>&lt;P&gt;Don't make us guess. What is wrong with the macro solution you provided?&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2020 12:29:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-report-color-cells/m-p/694223#M211705</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-26T12:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: proc report-color cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-report-color-cells/m-p/694228#M211707</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You have used vector1 call in %let I think that is a typo error but you macro works well if that is corrected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="language-sas"&gt;&lt;CODE&gt;%let vector =Val2009+Val2006+Val2003+Val1912;
%let k=4;

%macro mmacro1; 
%do j=1 %to &amp;amp;k.;
%let Val=%scan(&amp;amp;vector1.,&amp;amp;j.,+);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2020 13:19:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-report-color-cells/m-p/694228#M211707</guid>
      <dc:creator>shweta_d_singh</dc:creator>
      <dc:date>2020-10-26T13:19:59Z</dc:date>
    </item>
    <item>
      <title>Re: proc report-color cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-report-color-cells/m-p/694266#M211718</link>
      <description>&lt;P&gt;Yes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Add a dummy right most column that is NOPRINT and have a compute block for it.&amp;nbsp; Because the dummy column is right most, all the values of the columns to the left are available for examination and manipulation.&amp;nbsp; Create an array of the columns that you want to highlight in the same manner and loop over that array for evaluating the criteria and applying the style.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Tip:&amp;nbsp; Default VAL: to lightgreen background means fewer CALLD DEFINE statements coded&lt;/EM&gt;&lt;/P&gt;
&lt;PRE&gt;proc report data=RedLights nowd;
  column Subject UCL1 UCL2 Val2009 Val2006 Val2003 Val1912 last;

  define Subject / display  'Subject/Number';

  define UCL1 / display  "Upper/Control/Limit #1";
  define UCL2 / display  "Upper/Control/Limit #2";

  define Val2009 / display 'SEP-2020' style(column)=[background=lightgreen];
  define Val2006 / display 'JUN-2020' style(column)=[background=lightgreen];
  define Val2003 / display 'MAR-2020' style(column)=[background=lightgreen];
  define Val1912 / display 'DEC-2019' style(column)=[background=lightgreen];

  define last / noprint;

compute last;

  array vals val2009 val2006 val2003 val1912;

  do index = 1 to dim (vals);
    val = vals(index);
    vname = vname(vals(index));

    if val &amp;lt;  UCL1 and val &amp;lt;  UCL2 then continue;

*    call execute('%put NOTE: ' || catx(' ', vname , val));  * debug;

    if val &amp;lt;= UCL1 and val &amp;gt;  UCL2 then&lt;BR /&gt;      call define(trim(vname),"style","style={background=pink}");&lt;BR /&gt;    else
    if val &amp;gt;  UCL1 and val &amp;lt;= UCL2 then&lt;BR /&gt;      call define(trim(vname),"style","style={background=lightpink}");&lt;BR /&gt;    else&lt;BR /&gt;      call define(trim(vname),"style","style={background=red}");
  end;

endcomp;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RichardADeVenezia_0-1603724492971.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51057i83172A4D39F557CF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RichardADeVenezia_0-1603724492971.png" alt="RichardADeVenezia_0-1603724492971.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2020 15:05:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-report-color-cells/m-p/694266#M211718</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-10-26T15:05:14Z</dc:date>
    </item>
    <item>
      <title>Re: proc report-color cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-report-color-cells/m-p/694436#M211776</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;Some questions please:&lt;/P&gt;
&lt;P&gt;1-Is it necessary to write the statement&lt;/P&gt;
&lt;P&gt;if val &amp;lt; UCL1 and val &amp;lt; UCL2 then continue;&lt;/P&gt;
&lt;P&gt;What is it used for?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Oct 2020 06:19:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-report-color-cells/m-p/694436#M211776</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-10-27T06:19:54Z</dc:date>
    </item>
    <item>
      <title>Re: proc report-color cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-report-color-cells/m-p/694467#M211792</link>
      <description>&lt;P&gt;The &lt;CODE&gt;continue&lt;/CODE&gt; statement skips to the next iteration of the loop.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When an iteration is skipped the default background color according to the &lt;CODE&gt;define &amp;lt;column&amp;gt; / style(column)= [background=&amp;lt;color&amp;gt;]&lt;/CODE&gt; will be in effect.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Oct 2020 09:48:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-report-color-cells/m-p/694467#M211792</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-10-27T09:48:13Z</dc:date>
    </item>
  </channel>
</rss>

