<?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 cell with DO LOOP in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Color-cell-with-DO-LOOP/m-p/546023#M151139</link>
    <description>&lt;P&gt;I found the solution.&lt;/P&gt;
&lt;P&gt;Posted in the question.&lt;/P&gt;</description>
    <pubDate>Tue, 26 Mar 2019 04:31:02 GMT</pubDate>
    <dc:creator>hhchenfx</dc:creator>
    <dc:date>2019-03-26T04:31:02Z</dc:date>
    <item>
      <title>Color cell with DO LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Color-cell-with-DO-LOOP/m-p/546020#M151138</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;I have 2 set of column: s1 s2 and v1 v2.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 2 column color_cell1 and color_cell2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If color_cell&lt;STRONG&gt;1&lt;/STRONG&gt;&amp;gt;0 then color S&lt;STRONG&gt;1&lt;/STRONG&gt; and V&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;If color_cell2&amp;gt;0 then color S2 and V2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I can do it with macro variable created separately as you can see in my main code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need a DO LOOP since my actual data has a lot of column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My Macro works!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the original separated one, each location check create 1 set of color&lt;/P&gt;
&lt;P&gt;In the Marco, it is the same set of color.&lt;/P&gt;
&lt;P&gt;Thus the color pattern not match&lt;/P&gt;
&lt;P&gt;(difficult to explain)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot.&lt;/P&gt;
&lt;P&gt;HHCFX&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*IT WORKS!*&lt;BR /&gt;
%macro xxx();

proc report data=have nowd;
column id v1 v2 s1 s2 color_cell_1 color_cell_2;

define s1/display;
define s2/display;

define v1/display;
define v2/display;
define color_cell_1/display;
define color_cell_2/display;

	%DO location=1 %to 2;
		compute  color_cell_&amp;amp;location;
			if color_cell_&amp;amp;location&amp;gt;0 then do;
				do i=&amp;amp;location+1;
				call define (i,"style","style={background=RED}");
				end;

				do j=&amp;amp;location+3;
				call define (j,"style","style={background=BIYG}");
				end;

			end;
		endcomp;
	%END;

	run;
%mend;

%xxx();run;&lt;/CODE&gt;&lt;/PRE&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;****MAIN CODE**************;
data have;
input ID s1 s2 v1 v2 color_cell_1 color_cell_2;
datalines;
1 1 1 1 1 0 1
2 1 2 3 0 0 0
3 1 2 3 1 1 0
4 9 8 7 4 1 1
;run;



*MACRO VARIABLE to apply to the 2 sets;
%let location1=1;
%let location2=2;


proc report data=have nowd;
column id v1 v2 s1 s2 color_cell_1 color_cell_2;

define s1/display;
define s2/display;

define v1/display;
define v2/display;
define color_cell_1/display;
define color_cell_2/display;


*for set v1 s1 based on color_cell1;
compute  color_cell_&amp;amp;location1;
	if color_cell_&amp;amp;location1&amp;gt;0 then do;
		do i=&amp;amp;location1+1;
		call define (i,"style","style={background=RED}");
		end;

		do j=&amp;amp;location1+3;
		call define (j,"style","style={background=RED}");
		end;
	end;
endcomp;

*for set v2 s2 based on color_cell2;
compute  color_cell_&amp;amp;location2;
	if color_cell_&amp;amp;location2&amp;gt;0 then do;
		do i=&amp;amp;location2+1;
		call define (i,"style","style={background=BIYG}");
		end;

		do j=&amp;amp;location2+3;
		call define (j,"style","style={background=BIYG}");
		end;
	end;
endcomp;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 04:30:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Color-cell-with-DO-LOOP/m-p/546020#M151138</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2019-03-26T04:30:37Z</dc:date>
    </item>
    <item>
      <title>Re: Color cell with DO LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Color-cell-with-DO-LOOP/m-p/546023#M151139</link>
      <description>&lt;P&gt;I found the solution.&lt;/P&gt;
&lt;P&gt;Posted in the question.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 04:31:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Color-cell-with-DO-LOOP/m-p/546023#M151139</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2019-03-26T04:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: Color cell with DO LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Color-cell-with-DO-LOOP/m-p/546028#M151141</link>
      <description>&lt;P&gt;I don't see a solution anywhere, but this works:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;****MAIN CODE**************;
data HAVE;
input ID V1 V2 S1 S2 COLOR_CELL_1 COLOR_CELL_2;
datalines;
1 1 1 1 1 0 1
2 1 2 3 0 0 0
3 1 2 3 1 1 0
4 9 8 7 4 1 1
run;

proc report data=HAVE nowd;
  column ID V1 V2 S1 S2 COLOR_CELL_1 COLOR_CELL_2;

  define S1/display;
  define S2/display;

  define V1/display;
  define V2/display;
  define COLOR_CELL_1/display;                 
  define COLOR_CELL_2/display;             

%macro loop;
  %local i;
  %do i=1 %to 2; 
  compute COLOR_CELL_&amp;amp;i;              
    if COLOR_CELL_&amp;amp;i.&amp;gt;0 then call define ("V&amp;amp;i","style","style={background=RED}");
    if COLOR_CELL_&amp;amp;i.&amp;gt;0 then call define ("S&amp;amp;i","style","style={background=RED}");
  endcomp;
  %end;
%mend; 
%loop

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&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="Capture.PNG" style="width: 376px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28203iB5034C8C573378F9/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.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>Tue, 26 Mar 2019 04:58:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Color-cell-with-DO-LOOP/m-p/546028#M151141</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-03-26T04:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: Color cell with DO LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Color-cell-with-DO-LOOP/m-p/546358#M151269</link>
      <description>&lt;P&gt;So you put the macro inside Proc Report.&lt;/P&gt;
&lt;P&gt;I put it outside.&lt;/P&gt;
&lt;P&gt;Nice to know.&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 01:33:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Color-cell-with-DO-LOOP/m-p/546358#M151269</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2019-03-27T01:33:59Z</dc:date>
    </item>
    <item>
      <title>Re: Color cell with DO LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Color-cell-with-DO-LOOP/m-p/546365#M151274</link>
      <description>&lt;P&gt;Oh I see what you are doing now. So convoluted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can write the 25 lines of code as:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	%do location=1 %to 2;
		compute COLOR_CELL_&amp;amp;location.;
			if COLOR_CELL_&amp;amp;location. &amp;gt; 0 then do;
				call define (&amp;amp;location.+1,"style","style={background=RED }");
				call define (&amp;amp;location.+3,"style","style={background=BIYG}");
			end;
		endcomp;
	%end
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Mar 2019 02:59:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Color-cell-with-DO-LOOP/m-p/546365#M151274</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-03-27T02:59:48Z</dc:date>
    </item>
  </channel>
</rss>

