<?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: no output on column formula with For loop and if()  to count repeated str in cells in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/no-output-on-column-formula-with-For-loop-and-if-to-count/m-p/479740#M72412</link>
    <description>&lt;P&gt;Your formula is returning an &lt;CODE class=" language-jsl"&gt;Empty()&lt;/CODE&gt; value.&amp;nbsp; The &lt;CODE class=" language-jsl"&gt;For()&lt;/CODE&gt; loop exits when &lt;CODE class=" language-jsl"&gt;l = 9&lt;/CODE&gt;.&amp;nbsp; The logic is that when &lt;CODE class=" language-jsl"&gt;l = 8&lt;/CODE&gt;&amp;nbsp;the loop returns to the incrementor then the test.&amp;nbsp; The test for &lt;CODE class=" language-jsl"&gt;l &amp;lt;= N Items( map )&lt;/CODE&gt; fails, returning an empty value.&amp;nbsp; What you need to do is to terminate the loop at the point the &lt;CODE class=" language-jsl"&gt;If()&lt;/CODE&gt; statement is true, then return the result.&amp;nbsp; Here is an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt3 &amp;lt;&amp;lt; New Column( "smap",
	character,
	formula(	
		res = "0:1:2:3:4:5:6:7";
		For( l = 0, l &amp;lt; 8, l++,
			If( N Rows( Loc( Words( :smap1, "," ), Char( l ) ) ) &amp;gt;= 3,
				res = Concat Items( Repeat( Insert( {}, Char( l ) ), 8 ), ":" );
				Break();
			);
		);
		res;
	)
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 16 Apr 2022 19:56:53 GMT</pubDate>
    <dc:creator>ErraticAttack</dc:creator>
    <dc:date>2022-04-16T19:56:53Z</dc:date>
    <item>
      <title>no output on column formula with For loop and if()  to count repeated str in cells</title>
      <link>https://community.jmp.com/t5/Discussions/no-output-on-column-formula-with-For-loop-and-if-to-count/m-p/479720#M72410</link>
      <description>&lt;P&gt;Hi, Below (section A) is my code for a formula in a new column and it is working. However, I want to use for loop to replace it. I tried on it(Section B) , but there is not output at all. I wonder if someone can give me some advice of my mistake on section B? the example of column smap1 is in attached table. Thanks&lt;BR /&gt;section A:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt3 &amp;lt;&amp;lt; new column("smap", character,
formula(	

	If(N Rows( Loc( Words( :smap1, "," ), "0" ) ) &amp;gt;= 3, "0:0:0:0:0:0:0:0",
	   N Rows( Loc( Words( :smap1, "," ), "1" ) ) &amp;gt;= 3, "1:1:1:1:1:1:1:1",
	   N Rows( Loc( Words( :smap1, "," ), "2" ) ) &amp;gt;= 3, "2:2:2:2:2:2:2:2",
	   N Rows( Loc( Words( :smap1, "," ), "3" ) ) &amp;gt;= 3, "3:3:3:3:3:3:3:3",
	   N Rows( Loc( Words( :smap1, "," ), "4" ) ) &amp;gt;= 3, "4:4:4:4:4:4:4:4",
	   N Rows( Loc( Words( :smap1, "," ), "5" ) ) &amp;gt;= 3, "5:5:5:5:5:5:5:5",
	   N Rows( Loc( Words( :smap1, "," ), "6" ) ) &amp;gt;= 3, "6:6:6:6:6:6:6:6",
	   N Rows( Loc( Words( :smap1, "," ), "7" ) ) &amp;gt;= 3, "7:7:7:7:7:7:7:7",
	   "0:1:2:3:4:5:6:7"
		
	);
);
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;section B:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt3 &amp;lt;&amp;lt; new column("smap", character,
formula(	

map={"0","1","2","3","4","5","6","7"};

for (l=1, l&amp;lt;=N items(map), l++,
	A=":"||map[l];
	B=map[l];
	If(N Rows( Loc( Words( :smap1, "," ), char(map[l])) )&amp;gt;= 3, concat(B,A,A,A,A,A,A,A),
	"0:1:2:3:4:5:6:7"
);
)
)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Jun 2023 16:57:10 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/no-output-on-column-formula-with-For-loop-and-if-to-count/m-p/479720#M72410</guid>
      <dc:creator>dadawasozo</dc:creator>
      <dc:date>2023-06-09T16:57:10Z</dc:date>
    </item>
    <item>
      <title>Re: no output on column formula with For loop and if()  to count repeated str in cells</title>
      <link>https://community.jmp.com/t5/Discussions/no-output-on-column-formula-with-For-loop-and-if-to-count/m-p/479740#M72412</link>
      <description>&lt;P&gt;Your formula is returning an &lt;CODE class=" language-jsl"&gt;Empty()&lt;/CODE&gt; value.&amp;nbsp; The &lt;CODE class=" language-jsl"&gt;For()&lt;/CODE&gt; loop exits when &lt;CODE class=" language-jsl"&gt;l = 9&lt;/CODE&gt;.&amp;nbsp; The logic is that when &lt;CODE class=" language-jsl"&gt;l = 8&lt;/CODE&gt;&amp;nbsp;the loop returns to the incrementor then the test.&amp;nbsp; The test for &lt;CODE class=" language-jsl"&gt;l &amp;lt;= N Items( map )&lt;/CODE&gt; fails, returning an empty value.&amp;nbsp; What you need to do is to terminate the loop at the point the &lt;CODE class=" language-jsl"&gt;If()&lt;/CODE&gt; statement is true, then return the result.&amp;nbsp; Here is an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt3 &amp;lt;&amp;lt; New Column( "smap",
	character,
	formula(	
		res = "0:1:2:3:4:5:6:7";
		For( l = 0, l &amp;lt; 8, l++,
			If( N Rows( Loc( Words( :smap1, "," ), Char( l ) ) ) &amp;gt;= 3,
				res = Concat Items( Repeat( Insert( {}, Char( l ) ), 8 ), ":" );
				Break();
			);
		);
		res;
	)
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Apr 2022 19:56:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/no-output-on-column-formula-with-For-loop-and-if-to-count/m-p/479740#M72412</guid>
      <dc:creator>ErraticAttack</dc:creator>
      <dc:date>2022-04-16T19:56:53Z</dc:date>
    </item>
  </channel>
</rss>

