<?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 Issue with conditional formatting (color) using 'for each row' and nested 'for' loop in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Issue-with-conditional-formatting-color-using-for-each-row-and/m-p/399370#M65023</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm on the tail end of a script where I've summarized a bunch of data in various columns (both numeric and character).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looping to format numeric cells meeting certain criteria is easy enough but I'm having some issue assigning a color for character columns that contain a certain substring.&lt;/P&gt;&lt;P&gt;For instance, a cell (with the following content:1,1,2,1,1,2,3,3) should be colored red because it contains at 1 occurrence of the character '3'.&lt;/P&gt;&lt;P&gt;If I specify the entire content of the cell, no problem but I try to look for '3' and color accordingly -&amp;gt;fails.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've added the scripts below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sebastien&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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-jsl"&gt;Names Default To Here( 1 );
clear log();

dt = New Table( "test",
	Add Rows( 8 ),

	New Column( "unique_group_id",
		Character,
		"Nominal",
		Set Values(
			{"ELN-19-0588-A", "ELN-19-0588-B", "ELN-19-0588-C", "ELN-19-0588-D",
			"ELN-19-0588-E", "ELN-19-0588-F", "ELN-19-0588-G", "ELN-19-0588-H"}
		),
		Set Display Width( 115 )
	),
	New Column( "FOB max",
		Character,
		"Nominal",
		Set Selected,
		Set Values(
			{"0,0,0,0,0,0,0,0,0,0", "0,0,0,0,0,0,0,0", "0,0,0,0,0,0,0,0",
			"0,0,3,0,0,1,0,2", "1,1,2,1,1,2,3,3", "0,0,0,0,0,0,0,0",
			"4,2,2,3,2,3,3,4", "1,0,0,1,1,1,1,1"}
		)
	),
	New Column( "glib1 % PBS - potatoe",
		Numeric,
		"Ordinal",
		Format( "Best", 12 ),
		Set Selected,
		Set Values( [100, 113.39, 108.3, 156.38, 822.21, 768.51, 487.2, 222.56] )
	),
	New Column( "calb (IHC) cere",
		Character,
		"Nominal",
		Set Values(
			{"0,0,0,0,0,0,0,0,0,0", "0,0,0,0,0,0,0,0", "0,0,0,0,0,0,0,0",
			"0,0,0,0,0,0,0,0", "3,4,3,4,3,3,3,4", "3,3,3,5,2,3,3,3",
			"0,0,0,0,0,0,0,0", "0,0,0,0,0,0,1,0"}
		)
	)
);
wait(2);


col=dt &amp;lt;&amp;lt;get column names;
show(col);
nc=n items(col);
show(nc);
//This first example works fine 

c="% PBS";

For(i=1,i&amp;lt;=nc,i++, if( Contains( col[i], c ),
	for each row(
	If(  as column(col[i])&amp;gt;200,		 
		 column(col[i]) &amp;lt;&amp;lt; color cells( "Light Red", Row())
	)
)));


//Does not work - it needs to be an exact match 
c="FOB";
b={"3"};//trying to look for cells in columns labelled with FOB whihc contains the character '3'
For(i=1,i&amp;lt;=nc,i++, if( Contains( col[i], c ),
	for each row(
	If(  contains(b,as column(col[i])),
		 column(col[i])&amp;lt;&amp;lt; color cells( "Light Red", Row())
	)
)));

wait (2);

//Works when specifying exactly the content of the cell(s) to match
c="FOB";
b={"1,1,2,1,1,2,3,3"};

For(i=1,i&amp;lt;=nc,i++, if( Contains( col[i], c ),
	for each row(
	If(  contains(b,as column(col[i])),
		 column(col[i])&amp;lt;&amp;lt; color cells( "Red", Row())
	)
)));


&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 10 Jun 2023 23:33:23 GMT</pubDate>
    <dc:creator>Sburel</dc:creator>
    <dc:date>2023-06-10T23:33:23Z</dc:date>
    <item>
      <title>Issue with conditional formatting (color) using 'for each row' and nested 'for' loop</title>
      <link>https://community.jmp.com/t5/Discussions/Issue-with-conditional-formatting-color-using-for-each-row-and/m-p/399370#M65023</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm on the tail end of a script where I've summarized a bunch of data in various columns (both numeric and character).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looping to format numeric cells meeting certain criteria is easy enough but I'm having some issue assigning a color for character columns that contain a certain substring.&lt;/P&gt;&lt;P&gt;For instance, a cell (with the following content:1,1,2,1,1,2,3,3) should be colored red because it contains at 1 occurrence of the character '3'.&lt;/P&gt;&lt;P&gt;If I specify the entire content of the cell, no problem but I try to look for '3' and color accordingly -&amp;gt;fails.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've added the scripts below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sebastien&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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-jsl"&gt;Names Default To Here( 1 );
clear log();

dt = New Table( "test",
	Add Rows( 8 ),

	New Column( "unique_group_id",
		Character,
		"Nominal",
		Set Values(
			{"ELN-19-0588-A", "ELN-19-0588-B", "ELN-19-0588-C", "ELN-19-0588-D",
			"ELN-19-0588-E", "ELN-19-0588-F", "ELN-19-0588-G", "ELN-19-0588-H"}
		),
		Set Display Width( 115 )
	),
	New Column( "FOB max",
		Character,
		"Nominal",
		Set Selected,
		Set Values(
			{"0,0,0,0,0,0,0,0,0,0", "0,0,0,0,0,0,0,0", "0,0,0,0,0,0,0,0",
			"0,0,3,0,0,1,0,2", "1,1,2,1,1,2,3,3", "0,0,0,0,0,0,0,0",
			"4,2,2,3,2,3,3,4", "1,0,0,1,1,1,1,1"}
		)
	),
	New Column( "glib1 % PBS - potatoe",
		Numeric,
		"Ordinal",
		Format( "Best", 12 ),
		Set Selected,
		Set Values( [100, 113.39, 108.3, 156.38, 822.21, 768.51, 487.2, 222.56] )
	),
	New Column( "calb (IHC) cere",
		Character,
		"Nominal",
		Set Values(
			{"0,0,0,0,0,0,0,0,0,0", "0,0,0,0,0,0,0,0", "0,0,0,0,0,0,0,0",
			"0,0,0,0,0,0,0,0", "3,4,3,4,3,3,3,4", "3,3,3,5,2,3,3,3",
			"0,0,0,0,0,0,0,0", "0,0,0,0,0,0,1,0"}
		)
	)
);
wait(2);


col=dt &amp;lt;&amp;lt;get column names;
show(col);
nc=n items(col);
show(nc);
//This first example works fine 

c="% PBS";

For(i=1,i&amp;lt;=nc,i++, if( Contains( col[i], c ),
	for each row(
	If(  as column(col[i])&amp;gt;200,		 
		 column(col[i]) &amp;lt;&amp;lt; color cells( "Light Red", Row())
	)
)));


//Does not work - it needs to be an exact match 
c="FOB";
b={"3"};//trying to look for cells in columns labelled with FOB whihc contains the character '3'
For(i=1,i&amp;lt;=nc,i++, if( Contains( col[i], c ),
	for each row(
	If(  contains(b,as column(col[i])),
		 column(col[i])&amp;lt;&amp;lt; color cells( "Light Red", Row())
	)
)));

wait (2);

//Works when specifying exactly the content of the cell(s) to match
c="FOB";
b={"1,1,2,1,1,2,3,3"};

For(i=1,i&amp;lt;=nc,i++, if( Contains( col[i], c ),
	for each row(
	If(  contains(b,as column(col[i])),
		 column(col[i])&amp;lt;&amp;lt; color cells( "Red", Row())
	)
)));


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:33:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Issue-with-conditional-formatting-color-using-for-each-row-and/m-p/399370#M65023</guid>
      <dc:creator>Sburel</dc:creator>
      <dc:date>2023-06-10T23:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with conditional formatting (color) using 'for each row' and nested 'for' loop</title>
      <link>https://community.jmp.com/t5/Discussions/Issue-with-conditional-formatting-color-using-for-each-row-and/m-p/399457#M65032</link>
      <description>&lt;P&gt;You were specifying your Contains() function backwards and you were making your comparisons JMP Lists.&amp;nbsp; Fix those and it works fine.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="txnelson_0-1625688127700.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/34026iCAC4B3FA831B79D9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="txnelson_0-1625688127700.png" alt="txnelson_0-1625688127700.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
clear log();

dt = New Table( "test",
	Add Rows( 8 ),

	New Column( "unique_group_id",
		Character,
		"Nominal",
		Set Values(
			{"ELN-19-0588-A", "ELN-19-0588-B", "ELN-19-0588-C", "ELN-19-0588-D",
			"ELN-19-0588-E", "ELN-19-0588-F", "ELN-19-0588-G", "ELN-19-0588-H"}
		),
		Set Display Width( 115 )
	),
	New Column( "FOB max",
		Character,
		"Nominal",
		Set Selected,
		Set Values(
			{"0,0,0,0,0,0,0,0,0,0", "0,0,0,0,0,0,0,0", "0,0,0,0,0,0,0,0",
			"0,0,3,0,0,1,0,2", "1,1,2,1,1,2,3,3", "0,0,0,0,0,0,0,0",
			"4,2,2,3,2,3,3,4", "1,0,0,1,1,1,1,1"}
		)
	),
	New Column( "glib1 % PBS - potatoe",
		Numeric,
		"Ordinal",
		Format( "Best", 12 ),
		Set Selected,
		Set Values( [100, 113.39, 108.3, 156.38, 822.21, 768.51, 487.2, 222.56] )
	),
	New Column( "calb (IHC) cere",
		Character,
		"Nominal",
		Set Values(
			{"0,0,0,0,0,0,0,0,0,0", "0,0,0,0,0,0,0,0", "0,0,0,0,0,0,0,0",
			"0,0,0,0,0,0,0,0", "3,4,3,4,3,3,3,4", "3,3,3,5,2,3,3,3",
			"0,0,0,0,0,0,0,0", "0,0,0,0,0,0,1,0"}
		)
	)
);
wait(2);


col=dt &amp;lt;&amp;lt;get column names(string);
show(col);
nc=n items(col);
show(nc);
//This first example works fine 

c="% PBS";

For(i=1,i&amp;lt;=nc,i++, if( Contains( col[i], c ),
	for each row(
	If(  as column(col[i])&amp;gt;200,		 
		 column(col[i]) &amp;lt;&amp;lt; color cells( "Light Red", Row())
	)
)));


//Does not work - it needs to be an exact match 
c = "FOB";
b = "3";//trying to look for cells in columns labelled with FOB whihc contains the character '3'
For( i = 1, i &amp;lt;= nc, i++,
	If( Contains( col[i], c ),
		For Each Row(
			If( Contains( As Column( col[i] ), b ),
				Column( col[i] ) &amp;lt;&amp;lt; color cells( "Light Red", Row() )
			);
		)
	)
);

wait (2);

//Works when specifying exactly the content of the cell(s) to match
c = "FOB";
b = "1,1,2,1,1,2,3,3";

For( i = 1, i &amp;lt;= nc, i++,
	If( Contains( col[i], c ),
		For Each Row(
			If( Contains( As Column( col[i] ), b ),
				Column( col[i] ) &amp;lt;&amp;lt; color cells( "Red", Row() )
			)
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jul 2021 20:02:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Issue-with-conditional-formatting-color-using-for-each-row-and/m-p/399457#M65032</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-07-07T20:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with conditional formatting (color) using 'for each row' and nested 'for' loop</title>
      <link>https://community.jmp.com/t5/Discussions/Issue-with-conditional-formatting-color-using-for-each-row-and/m-p/399477#M65035</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Change your code to match line 67 in the code below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Contains ( ) lets you do a couple of different things, depending on the arguments you supply. For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Contains ( {"cat", "dog", "mouse", "dog", "horse"}, "dog" ) returns 2, because the first occurrence of "dog" in supplied list is at position 2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Contains ( {"cattle", "dog", "mouse"}, "cat") returns 0, as "cat" does not occur in the list. If we want to search the list element by element to see whether "cat" is a substring of any element, we have to iterate through the list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your original code is a bit like this last example: Contains (b, :col) checks whether the column cell value matches any element in b, which you've defined as {"3"}. No match is found.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Conversely, the new code, Contains(:col, b[1]), checks whether b[1], the first element of list b, which is "3", is contained in the column cell value. Used this way, the Contains (&amp;lt;&amp;lt;whole&amp;gt;&amp;gt;, &amp;lt;&amp;lt;part&amp;gt;&amp;gt;) function looks for substring &amp;lt;&amp;lt;part&amp;gt;&amp;gt; within string &amp;lt;&amp;lt;whole&amp;gt;&amp;gt;--which is what I believe you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Brady&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Contains ( {"cat", "dog", "mouse"}, "cat") returns&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="brady_brady_1-1625688525325.png" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/34029iFF8BF602FDE44204/image-size/large?v=v2&amp;amp;px=999" role="button" title="brady_brady_1-1625688525325.png" alt="brady_brady_1-1625688525325.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>Wed, 07 Jul 2021 20:20:14 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Issue-with-conditional-formatting-color-using-for-each-row-and/m-p/399477#M65035</guid>
      <dc:creator>brady_brady</dc:creator>
      <dc:date>2021-07-07T20:20:14Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with conditional formatting (color) using 'for each row' and nested 'for' loop</title>
      <link>https://community.jmp.com/t5/Discussions/Issue-with-conditional-formatting-color-using-for-each-row-and/m-p/399490#M65036</link>
      <description>Thanks!</description>
      <pubDate>Wed, 07 Jul 2021 21:46:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Issue-with-conditional-formatting-color-using-for-each-row-and/m-p/399490#M65036</guid>
      <dc:creator>Sburel</dc:creator>
      <dc:date>2021-07-07T21:46:59Z</dc:date>
    </item>
  </channel>
</rss>

