<?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: Simple Question about Loops in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Simple-Question-about-Loops/m-p/229198#M45458</link>
    <description>&lt;P&gt;The task you are wanting to do can be accomplished in two ways:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;a) use a Formula property for the column:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = current data table ();
tr = N Rows (dt);
dt &amp;lt;&amp;lt; New Column ("TEST", "CHARACTER", 
Formula(
	If( 
		(:TIME == "BASELINE" &amp;amp; :VALUE &amp;gt; 3)
		,"YES"
		,"NO"
		)
	)
				)
	;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;b)&amp;nbsp; iterate with a loop&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = current data table ();

dt &amp;lt;&amp;lt; New Column ("TEST", "CHARACTER", Character, Nominal);
for(ii=1, ii&amp;lt;=N Rows(dt), ii++, 
:test[ii]=If( 
		(:TIME[ii] == "BASELINE" &amp;amp; :VALUE[ii] &amp;gt; 3)
		,"YES"
		,"NO"
		)
	);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;you can also use For Each Row()&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = current data table ();

dt &amp;lt;&amp;lt; New Column ("TEST", "CHARACTER", Character, Nominal);
for each row( 
:test=If( 
		(:TIME == "BASELINE" &amp;amp; :VALUE &amp;gt; 3)
		,"YES"
		,"NO"
		)
	);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 13 Oct 2019 21:35:15 GMT</pubDate>
    <dc:creator>MathStatChem</dc:creator>
    <dc:date>2019-10-13T21:35:15Z</dc:date>
    <item>
      <title>Simple Question about Loops</title>
      <link>https://community.jmp.com/t5/Discussions/Simple-Question-about-Loops/m-p/229183#M45453</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm a longtime JMP user, but just recently started learning about scripts. I'm trying to learn the basics, and one of the key things I want to master is the use of for loops.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I created a sample dataset with 4 columns:&lt;/P&gt;&lt;P&gt;1) PATIENTID: list of unique values for patient number&lt;BR /&gt;2) VALUE: Value of a patient rating at a particular timepoint&lt;BR /&gt;3) TIME: Timepoint at which patient rating was collected&lt;BR /&gt;4) PARAM: The patient rating is divided into 4 items and a total score&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrote a script to iterate through all of the rows in this data table and to evaluate the values of two different variables (:TIME and :VALUE). If the condition is met, I'd like to add a character value to a row in a new column which is either Yes or No.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the script that I wrote. JMP returns empty values for each of the rows in the new column:&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 );
dt = current data table ();
tr = N Rows (dt);
dt &amp;lt;&amp;lt; New Column ("TEST", "CHARACTER", 
For (i = 1, i &amp;lt;= tr, i++,
	If( 
		(:TIME == "BASELINE" &amp;amp; :VALUE &amp;gt; 3)
		,"YES"
		,"NO"
		)
	)
				)
	;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is a simple script, and once I understand the mechanics, would like to add more conditions. But am stuck at this point because the script is not working properly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also tried writing this script using the For Each Row function, but still am having the same problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any advice on what I'm doing wrong? Sorry if this is a simple answer, I looked through the documentation and can't seem to figure out what I'm doing wrong.&lt;/P&gt;</description>
      <pubDate>Sun, 13 Oct 2019 16:25:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Simple-Question-about-Loops/m-p/229183#M45453</guid>
      <dc:creator>SrihariGopal</dc:creator>
      <dc:date>2019-10-13T16:25:03Z</dc:date>
    </item>
    <item>
      <title>Re: Simple Question about Loops</title>
      <link>https://community.jmp.com/t5/Discussions/Simple-Question-about-Loops/m-p/229193#M45454</link>
      <description>&lt;P&gt;Here is a similar script that I wrote to accomplish the same task, but instead using the &lt;EM&gt;For Each Row&lt;/EM&gt; function. This doesn't work either.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = current data table ();
dt &amp;lt;&amp;lt; New Column ("TEST", "CHARACTER", 
For Each Row (dt, 
	If (
		(:TIME == "BASELINE" &amp;amp; :VALUE &amp;gt; 3)
		,"YES"
		,"NO"
		)
	)
				)
	;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any help appreciated&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Oct 2019 16:30:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Simple-Question-about-Loops/m-p/229193#M45454</guid>
      <dc:creator>SrihariGopal</dc:creator>
      <dc:date>2019-10-13T16:30:35Z</dc:date>
    </item>
    <item>
      <title>Re: Simple Question about Loops</title>
      <link>https://community.jmp.com/t5/Discussions/Simple-Question-about-Loops/m-p/229194#M45455</link>
      <description>One more question:&lt;BR /&gt;The JSL documentation says that the for loops are incremented using the 3rd argument in the For function. I've seen this typically written as i++. I assume this means to increment i in place by 1. But what do I do if I want to increment by values less than 1? How do I write the argument?&lt;BR /&gt;&lt;BR /&gt;The JSL documentation and the scripting index tool don't make any mention of how to do this.&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Sun, 13 Oct 2019 16:37:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Simple-Question-about-Loops/m-p/229194#M45455</guid>
      <dc:creator>SrihariGopal</dc:creator>
      <dc:date>2019-10-13T16:37:35Z</dc:date>
    </item>
    <item>
      <title>Re: Simple Question about Loops</title>
      <link>https://community.jmp.com/t5/Discussions/Simple-Question-about-Loops/m-p/229198#M45458</link>
      <description>&lt;P&gt;The task you are wanting to do can be accomplished in two ways:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;a) use a Formula property for the column:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = current data table ();
tr = N Rows (dt);
dt &amp;lt;&amp;lt; New Column ("TEST", "CHARACTER", 
Formula(
	If( 
		(:TIME == "BASELINE" &amp;amp; :VALUE &amp;gt; 3)
		,"YES"
		,"NO"
		)
	)
				)
	;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;b)&amp;nbsp; iterate with a loop&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = current data table ();

dt &amp;lt;&amp;lt; New Column ("TEST", "CHARACTER", Character, Nominal);
for(ii=1, ii&amp;lt;=N Rows(dt), ii++, 
:test[ii]=If( 
		(:TIME[ii] == "BASELINE" &amp;amp; :VALUE[ii] &amp;gt; 3)
		,"YES"
		,"NO"
		)
	);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;you can also use For Each Row()&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = current data table ();

dt &amp;lt;&amp;lt; New Column ("TEST", "CHARACTER", Character, Nominal);
for each row( 
:test=If( 
		(:TIME == "BASELINE" &amp;amp; :VALUE &amp;gt; 3)
		,"YES"
		,"NO"
		)
	);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Oct 2019 21:35:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Simple-Question-about-Loops/m-p/229198#M45458</guid>
      <dc:creator>MathStatChem</dc:creator>
      <dc:date>2019-10-13T21:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: Simple Question about Loops</title>
      <link>https://community.jmp.com/t5/Discussions/Simple-Question-about-Loops/m-p/229199#M45459</link>
      <description>&lt;P&gt;It does not work because the loop is placed inside the New Column definition. Either create the column and fill its values in separate statements, or use a column formula.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Look at these three jsl examples that should give identical result:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
dt = Current Data Table();
tr = N Rows(dt);

//1. Fill values with a For() loop
dt &amp;lt;&amp;lt; New Column("TEST", "CHARACTER");
For(i = 1, i &amp;lt;= tr, i++,
    :TEST[i] = If(:TIME[i] == "BASELINE" &amp;amp; :VALUE[i] &amp;gt; 3,
        "YES",
        "NO"
    )
);

//2. Fill with For Each Row()

dt &amp;lt;&amp;lt; New Column("TEST2", "CHARACTER");
For Each Row(:TEST2 = If(:TIME == "BASELINE" &amp;amp; :VALUE &amp;gt; 3, "YES", "NO"));

//3. Use a column formula in TEST3
dt &amp;lt;&amp;lt; New Column("TEST3",
    "CHARACTER",
    Formula(If(:TIME == "BASELINE" &amp;amp; :VALUE &amp;gt; 3, "YES", "NO"))
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Oct 2019 21:49:47 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Simple-Question-about-Loops/m-p/229199#M45459</guid>
      <dc:creator>ms</dc:creator>
      <dc:date>2019-10-13T21:49:47Z</dc:date>
    </item>
    <item>
      <title>Re: Simple Question about Loops</title>
      <link>https://community.jmp.com/t5/Discussions/Simple-Question-about-Loops/m-p/229200#M45460</link>
      <description>&lt;P&gt;Loops are usually used for iterating through table rows or over items in a list, hence an increment by one is most common. However, the third argument must not be i++. It could be anything that makes sense.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A few examples:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;
For(i = 1, i &amp;lt;= 10, i = i + 0.1, Expr()); // Increment &amp;lt; 1 (100 iterations)

For(i = 10, i &amp;gt; 1, i--, Expr()); // Loop "backwards"

For(x = 2, x &amp;lt;= 10, x = 2, Expr()); // Eternal loop (better avoid these)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Oct 2019 22:19:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Simple-Question-about-Loops/m-p/229200#M45460</guid>
      <dc:creator>ms</dc:creator>
      <dc:date>2019-10-13T22:19:35Z</dc:date>
    </item>
  </channel>
</rss>

