<?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: creating new columns with a for loop with column names and formula in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/creating-new-columns-with-a-for-loop-with-column-names-and/m-p/664212#M85257</link>
    <description>&lt;P&gt;JMP formula definition will not evaluate when being defined, only when run.&amp;nbsp; Therefore, the formula needs to be presented to JMP in a fully defined form.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Column( colname[i] ) /  Column( colby[i] )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;needs to presented to JMP as&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Column( "B" ) / Column( "A" )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Using the Substitute function allows for the expanding of the code as required&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// Add new columns to the split data table
For( i = 1, i &amp;lt;= N Items( colname ), i++,
	Eval(
		Substitute(
				Expr(
					dt2 &amp;lt;&amp;lt; New Column( colname[i] || "/" || colby[i],
						Numeric,
						"Continuous",
						Format( "Best", 12 ),
						Formula( Column( __colname__ ) / Column( __colby__ ) )
					)
				),
			Expr( __colname__ ), colname[i],
			Expr( __colby__ ), colby[i]
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 31 Jul 2023 20:56:46 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2023-07-31T20:56:46Z</dc:date>
    <item>
      <title>creating new columns with a for loop with column names and formula</title>
      <link>https://community.jmp.com/t5/Discussions/creating-new-columns-with-a-for-loop-with-column-names-and/m-p/664207#M85256</link>
      <description>&lt;P&gt;I am trying to create a split table from an existing table and add new columns into the split tables each with a formula based on the columns that were split. However the code creates the new columns but gives me "Formula evaluation errors"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt2 = Current Data Table();

// Create the split data table
dt2 = dt &amp;lt;&amp;lt; Split(
	Split By( :S ),
	Split(
				:Name( "Median(data)" )
			),
	Group( :L, :m, :C, :P, :z, :x ),
	Remaining Columns( Drop All ),
	Sort by Column Property
);
colname = {"B","C"};
colby = {"A","B"};

// Add new columns to the split data table
For( i = 1, i &amp;lt;= N Items( colname ), i++,
dt2 &amp;lt;&amp;lt; New Column( colname[i]||"/"||colby[i],
	Numeric,
	"Continuous",
	Format( "Best", 12 ),
	Formula( column(colname[i]) / column(colby[i]) )
););&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Jul 2023 20:34:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/creating-new-columns-with-a-for-loop-with-column-names-and/m-p/664207#M85256</guid>
      <dc:creator>FrequencyBison9</dc:creator>
      <dc:date>2023-07-31T20:34:09Z</dc:date>
    </item>
    <item>
      <title>Re: creating new columns with a for loop with column names and formula</title>
      <link>https://community.jmp.com/t5/Discussions/creating-new-columns-with-a-for-loop-with-column-names-and/m-p/664212#M85257</link>
      <description>&lt;P&gt;JMP formula definition will not evaluate when being defined, only when run.&amp;nbsp; Therefore, the formula needs to be presented to JMP in a fully defined form.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Column( colname[i] ) /  Column( colby[i] )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;needs to presented to JMP as&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Column( "B" ) / Column( "A" )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Using the Substitute function allows for the expanding of the code as required&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// Add new columns to the split data table
For( i = 1, i &amp;lt;= N Items( colname ), i++,
	Eval(
		Substitute(
				Expr(
					dt2 &amp;lt;&amp;lt; New Column( colname[i] || "/" || colby[i],
						Numeric,
						"Continuous",
						Format( "Best", 12 ),
						Formula( Column( __colname__ ) / Column( __colby__ ) )
					)
				),
			Expr( __colname__ ), colname[i],
			Expr( __colby__ ), colby[i]
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Jul 2023 20:56:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/creating-new-columns-with-a-for-loop-with-column-names-and/m-p/664212#M85257</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2023-07-31T20:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: creating new columns with a for loop with column names and formula</title>
      <link>https://community.jmp.com/t5/Discussions/creating-new-columns-with-a-for-loop-with-column-names-and/m-p/664234#M85259</link>
      <description>&lt;P&gt;I am still getting the same error, as below&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Column B/A Formula Interrupted
Cannot convert argument to a number [or matrix] 1 times At rows: 2 Operation: Divide, Column( "B" ) /  /*###*/Column( "A" ) /*###*/
Formula evaluation errors have been ignored

Column C/B Formula Interrupted
Cannot convert argument to a number [or matrix] 1 times At rows: 2 Operation: Divide, Column( "C" ) /  /*###*/Column( "B" ) /*###*/
Formula evaluation errors have been ignored&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Jul 2023 22:26:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/creating-new-columns-with-a-for-loop-with-column-names-and/m-p/664234#M85259</guid>
      <dc:creator>FrequencyBison9</dc:creator>
      <dc:date>2023-07-31T22:26:55Z</dc:date>
    </item>
    <item>
      <title>Re: creating new columns with a for loop with column names and formula</title>
      <link>https://community.jmp.com/t5/Discussions/creating-new-columns-with-a-for-loop-with-column-names-and/m-p/664264#M85261</link>
      <description>&lt;P&gt;Try changing the Column() function to As Column() function&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2023 00:52:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/creating-new-columns-with-a-for-loop-with-column-names-and/m-p/664264#M85261</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2023-08-01T00:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: creating new columns with a for loop with column names and formula</title>
      <link>https://community.jmp.com/t5/Discussions/creating-new-columns-with-a-for-loop-with-column-names-and/m-p/664442#M85281</link>
      <description>&lt;P&gt;That worked, thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2023 15:48:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/creating-new-columns-with-a-for-loop-with-column-names-and/m-p/664442#M85281</guid>
      <dc:creator>FrequencyBison9</dc:creator>
      <dc:date>2023-08-01T15:48:28Z</dc:date>
    </item>
  </channel>
</rss>

