<?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 Proper syntax to call Formula within Loop in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Proper-syntax-to-call-Formula-within-Loop/m-p/16790#M15305</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, I would like to quickly enter multiple columns with the same overall formula but different variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried the following but clearly, I'm not using the proper syntax to call the Fomula item in the New Column function:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Names Default to Here (1);&lt;/P&gt;&lt;P&gt;dt = Current Data Table ();&lt;/P&gt;&lt;P&gt;cc = N col (dt); // Retain the original column number&lt;/P&gt;&lt;P&gt;For (i=9,i&amp;lt;= cc, i = i+2,&lt;/P&gt;&lt;P&gt;&amp;nbsp; New column ("Delta " || Column Name (i+1),&lt;/P&gt;&lt;P&gt;&amp;nbsp; numeric,&lt;/P&gt;&lt;P&gt;&amp;nbsp; continuous,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="color: #ff0000;"&gt;Formula (:Column Name(i+1) - :Column Name (i)) // Problem with Syntax&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; );&lt;/P&gt;&lt;P&gt;);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sincerely.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 08 Feb 2016 18:59:42 GMT</pubDate>
    <dc:creator>sornasst</dc:creator>
    <dc:date>2016-02-08T18:59:42Z</dc:date>
    <item>
      <title>Proper syntax to call Formula within Loop</title>
      <link>https://community.jmp.com/t5/Discussions/Proper-syntax-to-call-Formula-within-Loop/m-p/16790#M15305</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, I would like to quickly enter multiple columns with the same overall formula but different variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried the following but clearly, I'm not using the proper syntax to call the Fomula item in the New Column function:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Names Default to Here (1);&lt;/P&gt;&lt;P&gt;dt = Current Data Table ();&lt;/P&gt;&lt;P&gt;cc = N col (dt); // Retain the original column number&lt;/P&gt;&lt;P&gt;For (i=9,i&amp;lt;= cc, i = i+2,&lt;/P&gt;&lt;P&gt;&amp;nbsp; New column ("Delta " || Column Name (i+1),&lt;/P&gt;&lt;P&gt;&amp;nbsp; numeric,&lt;/P&gt;&lt;P&gt;&amp;nbsp; continuous,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="color: #ff0000;"&gt;Formula (:Column Name(i+1) - :Column Name (i)) // Problem with Syntax&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; );&lt;/P&gt;&lt;P&gt;);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sincerely.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Feb 2016 18:59:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Proper-syntax-to-call-Formula-within-Loop/m-p/16790#M15305</guid>
      <dc:creator>sornasst</dc:creator>
      <dc:date>2016-02-08T18:59:42Z</dc:date>
    </item>
    <item>
      <title>Re: Proper syntax to call Formula within Loop</title>
      <link>https://community.jmp.com/t5/Discussions/Proper-syntax-to-call-Formula-within-Loop/m-p/16791#M15306</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;this script might build something close to what you are after.&amp;nbsp; the Formula parameter to the New Column function needs a completely built formula, in the form it needs to be in when it actually runs, which is after your script runs.&amp;nbsp; the eval( evalexpr( ... expr(...) ... expr(...) ... ) ) strategy below is one way to do what you need.&amp;nbsp; expr() is used to tag the parts that need to be evaluated.&amp;nbsp; evalexpr() hunts them down and evaluates them.&amp;nbsp; eval() evaluates the expression returned by evalexpr.&amp;nbsp; Note the minus between the two expr() is NOT evaluated inside the for loop, but names[i+1] IS evaluated (by evalexpr) and NewColumn IS evaluated (by eval).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;&amp;lt;GetColumnNames returns a list of the table's column names.&amp;nbsp; char() makes a string for concatenation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;dt = New Table( "Untitled",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; Add Rows( 1 ),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; New Column( "a", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1] ) ),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; New Column( "b", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2] ) ),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; New Column( "c", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [4] ) ),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; New Column( "d", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [8] ) ),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; New Column( "e", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [16] ) ),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; New Column( "f", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [32] ) )&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;cc = N col (dt); &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;names=dt&amp;lt;&amp;lt;getColumnNames;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;For( i = 1, i &amp;lt;= cc, i = i + 2,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; Eval( // evaluate the expression returned by...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; Eval Expr( // evaluate the embedded expr...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; New Column( "Delta " || char(names[ i + 1 ]), // convert the column to a string&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; numeric, continuous,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; // Formula won't evaluate on&amp;nbsp; its own.&amp;nbsp; Needs TWO expr for this case&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; Formula( Expr( names[ i + 1 ] ) - Expr( names[ i ] ) )&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; )&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; )&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; )&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;/* ----- resulting script -----------------&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;New Table( "Untitled",&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; Add Rows( 1 ),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; New Column( "a", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1] ) ),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; New Column( "b", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2] ) ),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; New Column( "c", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [4] ) ),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; New Column( "d", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [8] ) ),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; New Column( "e", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [16] ) ),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; New Column( "f", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [32] ) ),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; New Column( "Delta b", Numeric, "Continuous", Format( "Best", 10 ), Formula( :p&lt;/img&gt; - :a ) ),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; New Column( "Delta d", Numeric, "Continuous", Format( "Best", 10 ), Formula( :d - :c ) ),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; New Column( "Delta f", Numeric, "Continuous", Format( "Best", 10 ), Formula( :f - :e ) )&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="10929_pastedImage_5.png" style="width: 915px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/2710iC1A9A1F3B0219715/image-size/medium?v=v2&amp;amp;px=400" role="button" title="10929_pastedImage_5.png" alt="10929_pastedImage_5.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Oct 2016 01:50:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Proper-syntax-to-call-Formula-within-Loop/m-p/16791#M15306</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2016-10-19T01:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: Proper syntax to call Formula within Loop</title>
      <link>https://community.jmp.com/t5/Discussions/Proper-syntax-to-call-Formula-within-Loop/m-p/16792#M15307</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Craig,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for sending me the correct code: I would not have been able to solve this by myself.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regarding the use of "Eval" and "Eval Expr", why is it necessary to combine these two functions? Would "Eval Expr" alone do the trick?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sincerely,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thierry&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Feb 2016 16:05:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Proper-syntax-to-call-Formula-within-Loop/m-p/16792#M15307</guid>
      <dc:creator>sornasst</dc:creator>
      <dc:date>2016-02-09T16:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: Proper syntax to call Formula within Loop</title>
      <link>https://community.jmp.com/t5/Discussions/Proper-syntax-to-call-Formula-within-Loop/m-p/16793#M15308</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;EvalExpr doesn't perform the eval because you'd often want the expression so you could continue working on it.&amp;nbsp; In this case, there was nothing else to do. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;evalexpr(3+4+expr(5+6))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3 + 4 + 11&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;JMP has powerful expression manipulation functions for performing surgery on expressions.&amp;nbsp; This is one example; arg, head, substituteinto are other functions that can work with expressions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.jmp.com/blogs/id/1099" target="_blank"&gt;Introspection&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.jmp.com/support/help/Lists_and_Expressions.shtml" title="http://www.jmp.com/support/help/Lists_and_Expressions.shtml" rel="noopener noreferrer" target="_blank"&gt;Lists and Expressions&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Nov 2016 10:05:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Proper-syntax-to-call-Formula-within-Loop/m-p/16793#M15308</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2016-11-09T10:05:26Z</dc:date>
    </item>
  </channel>
</rss>

