<?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 formula using dynamic variables in for loop in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Creating-formula-using-dynamic-variables-in-for-loop/m-p/662751#M85150</link>
    <description>&lt;P&gt;And as usual, finally I got one solution, fell free to replay with more efficient script.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For(i = 1, i &amp;lt;= N Items(Tweak_List), i++, 
 
	Eval(
		Eval Expr(
			dt &amp;lt;&amp;lt; New Column(Left(Tweak_List[i], Length(Tweak_List[i]) - 1) || "Δ",
				Numeric,
				"Continuous",
				Formula(
					If(:ENTITY == :ENTITY_2,
						As Column(Expr(Char(Left(Tweak_List[i], Length(Tweak_List[i]) - 2)))) - As Column(Expr(Char(Tweak_List[i]))),
						0
					)
				)
			)
		)
	);
 
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;From iH:&amp;nbsp;&lt;A href="https://community.jmp.com/t5/JSL-Cookbook-Archived/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/ta-p/48998" target="_blank" rel="noopener"&gt;https://community.jmp.com/t5/JSL-Cookbook-Archived/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/ta-p/48998&lt;/A&gt;&amp;nbsp;&lt;/DIV&gt;</description>
    <pubDate>Thu, 27 Jul 2023 04:41:01 GMT</pubDate>
    <dc:creator>Miof</dc:creator>
    <dc:date>2023-07-27T04:41:01Z</dc:date>
    <item>
      <title>Creating formula using dynamic variables in for loop</title>
      <link>https://community.jmp.com/t5/Discussions/Creating-formula-using-dynamic-variables-in-for-loop/m-p/662740#M85147</link>
      <description>&lt;P&gt;Hi All&lt;BR /&gt;I did that one time, and it was painfully but I lost the script and the memory of that. Below what I am trying to do:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Tweak_List = dt_Temp &amp;lt;&amp;lt; Get Column Names("String");
For(i = 1, i &amp;lt;= N Items(Tweak_List), i++, 
 
	a = Left(Tweak_List[i], Length(Tweak_List[i]) - 1) || "Δ";
	b = Tweak_List[i];
	c = Left(Tweak_List[i], Length(Tweak_List[i]) - 2);
 
	dt &amp;lt;&amp;lt; New Column(Left(Tweak_List[i], Length(Tweak_List[i]) - 1) || "Δ", Numeric, Continuous, Formula(If(:name1 == :name2, c - b, 0)));
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;In dt I have columns named ColName_2 and ColName, the Tweak_List is the list of names of columns like ColName_2.&lt;BR /&gt;I need do create a new Delta Column named ColName_&lt;SPAN&gt;Δ&lt;/SPAN&gt; for each pair and have the formula&amp;nbsp;&amp;nbsp;ColName -&amp;nbsp;ColName_2 in it is a condition is meet.&lt;BR /&gt;I remember I was working with Eval and Co, but I forgot. Pls help me&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 27 Jul 2023 04:40:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Creating-formula-using-dynamic-variables-in-for-loop/m-p/662740#M85147</guid>
      <dc:creator>Miof</dc:creator>
      <dc:date>2023-07-27T04:40:31Z</dc:date>
    </item>
    <item>
      <title>Re: Creating formula using dynamic variables in for loop</title>
      <link>https://community.jmp.com/t5/Discussions/Creating-formula-using-dynamic-variables-in-for-loop/m-p/662751#M85150</link>
      <description>&lt;P&gt;And as usual, finally I got one solution, fell free to replay with more efficient script.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For(i = 1, i &amp;lt;= N Items(Tweak_List), i++, 
 
	Eval(
		Eval Expr(
			dt &amp;lt;&amp;lt; New Column(Left(Tweak_List[i], Length(Tweak_List[i]) - 1) || "Δ",
				Numeric,
				"Continuous",
				Formula(
					If(:ENTITY == :ENTITY_2,
						As Column(Expr(Char(Left(Tweak_List[i], Length(Tweak_List[i]) - 2)))) - As Column(Expr(Char(Tweak_List[i]))),
						0
					)
				)
			)
		)
	);
 
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;From iH:&amp;nbsp;&lt;A href="https://community.jmp.com/t5/JSL-Cookbook-Archived/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/ta-p/48998" target="_blank" rel="noopener"&gt;https://community.jmp.com/t5/JSL-Cookbook-Archived/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/ta-p/48998&lt;/A&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 27 Jul 2023 04:41:01 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Creating-formula-using-dynamic-variables-in-for-loop/m-p/662751#M85150</guid>
      <dc:creator>Miof</dc:creator>
      <dc:date>2023-07-27T04:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: Creating formula using dynamic variables in for loop</title>
      <link>https://community.jmp.com/t5/Discussions/Creating-formula-using-dynamic-variables-in-for-loop/m-p/662786#M85154</link>
      <description>&lt;P&gt;You could use Word() or Words() instead of Left().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = New Table("Untitled 143",
	Add Rows(1),
	Compress File When Saved(1),
	New Column("Column1", Numeric, "Continuous", Format("Best", 12), Set Values([1])),
	New Column("Column1_2", Numeric, "Continuous", Format("Best", 12), Set Values([2])),
	New Column("Column2", Numeric, "Continuous", Format("Best", 12), Set Values([3])),
	New Column("Column2_2", Numeric, "Continuous", Format("Best", 12), Set Values([4]))
);

tweaklist = {"Column1_2", "Column2_2"};

For Each({col_name}, tweaklist,
	Eval(EvalExpr(
		dt &amp;lt;&amp;lt; New Column(Word(1, col_name, "_") || "_Δ", Numeric, Continuous, Formula(
			Expr(Name Expr(As Column(col_name))) - Expr(Name Expr(As Column(Word(1, col_name, "_"))))
		));
	));
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also if you don't need the formula but just the values, you could use &amp;lt;&amp;lt; Set Each Value which doesn't need as heavy evaluation&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For Each({col_name}, tweaklist,
	dt &amp;lt;&amp;lt; New Column(Word(1, col_name, "_") || "_Δ", Numeric, Continuous, &amp;lt;&amp;lt; Set Each Value(
		As Column(col_name) - As Column(Word(1, col_name, "_"))
	));
);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Jul 2023 05:04:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Creating-formula-using-dynamic-variables-in-for-loop/m-p/662786#M85154</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-07-27T05:04:45Z</dc:date>
    </item>
  </channel>
</rss>

