<?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: Create new column with formula saved as a variable in a script in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Create-new-column-with-formula-saved-as-a-variable-in-a-script/m-p/556314#M77023</link>
    <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Fri, 14 Oct 2022 11:36:17 GMT</pubDate>
    <dc:creator>thedellette</dc:creator>
    <dc:date>2022-10-14T11:36:17Z</dc:date>
    <item>
      <title>Create new column with formula saved as a variable in a script</title>
      <link>https://community.jmp.com/t5/Discussions/Create-new-column-with-formula-saved-as-a-variable-in-a-script/m-p/556158#M77013</link>
      <description>&lt;P&gt;I am using a script to extract a predicted formula from some data that I have, I then modify that formula using substitution and would now like to make a new column using the modified formula. I think this is easy but when I try to script this the formula saved as a variable is not recognized. Any help would be greatly appreciated, please let me know if you need more information as well.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;//Script that just shows saving the formula as a variable fm and modifying the variable using substitute to fm2

fm = report(obj1)[OutlineBox("Polynomial ?")][TextEditBox(1)] &amp;lt;&amp;lt; get text;
//get the string to the right of the equal sign and convert the string to an expression using Parse()
fm = Parse(Trim(word(2, fm, "=")));
fm2 = Substitute(NameExpr(fm), EvalExpr(LnTime2), EvalExpr(log(Time2)));

 

//Script to create a new column with the fm2 formula that does not work

dt &amp;lt;&amp;lt; New Column( "Predicted", Numeric, Formula (fm2));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;//Here is what is returned in the Log when you print fm2 in the script&lt;/P&gt;
&lt;P&gt;Print(fm2);&lt;/P&gt;
&lt;P&gt;(-0.270568) + 0.0352458 * Log(Time2) - 0.0331127 * (Log(Time2) - 7.22484) ^ 2 + 0.0046766 * (Log(Time2) - 7.22484) ^ 3 + 0.0075752 * (Log(Time2) - 7.22484) ^ 4 + 0.0012501 * (Log(Time2) - 7.22484) ^ 5 + 0.000026534 * (Log(Time2) - 7.22484) ^ 6&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 16:00:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-new-column-with-formula-saved-as-a-variable-in-a-script/m-p/556158#M77013</guid>
      <dc:creator>thedellette</dc:creator>
      <dc:date>2023-06-09T16:00:15Z</dc:date>
    </item>
    <item>
      <title>Re: Create new column with formula saved as a variable in a script</title>
      <link>https://community.jmp.com/t5/Discussions/Create-new-column-with-formula-saved-as-a-variable-in-a-script/m-p/556183#M77016</link>
      <description>&lt;P&gt;Try this instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Eval(
	Substitute(
		Expr( dt &amp;lt;&amp;lt; New Column( "Predicted", Numeric, Formula ( fff ) ) ),
		Expr( fff ), Name Expr( fm2 )
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Oct 2022 20:44:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-new-column-with-formula-saved-as-a-variable-in-a-script/m-p/556183#M77016</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2022-10-13T20:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: Create new column with formula saved as a variable in a script</title>
      <link>https://community.jmp.com/t5/Discussions/Create-new-column-with-formula-saved-as-a-variable-in-a-script/m-p/556204#M77017</link>
      <description>&lt;P&gt;I would keep the formula as a string, substitute within it, adding a ":" to let know JMP you are dealing with a column and then use&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;eval(parse())&lt;/P&gt;
&lt;P&gt;to execute it.&amp;nbsp; Here is a simple exampel&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);
dt=current data table();

fm="height";
fm2 = substitute(fm, expr("height"), "log(:height)");

eval(parse("dt &amp;lt;&amp;lt; new column (\!"predicted\!",numeric,formula(" || fm2 || "));"));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Oct 2022 21:47:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-new-column-with-formula-saved-as-a-variable-in-a-script/m-p/556204#M77017</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2022-10-13T21:47:44Z</dc:date>
    </item>
    <item>
      <title>Re: Create new column with formula saved as a variable in a script</title>
      <link>https://community.jmp.com/t5/Discussions/Create-new-column-with-formula-saved-as-a-variable-in-a-script/m-p/556313#M77022</link>
      <description>&lt;P&gt;Thanks for the tip to keep the formula as a string and adding&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;":" to let JMP know if is a column. I couldn't get the eval(parse()) to work, I was unsure why the double quote was needed in this as well.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2022 11:35:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-new-column-with-formula-saved-as-a-variable-in-a-script/m-p/556313#M77022</guid>
      <dc:creator>thedellette</dc:creator>
      <dc:date>2022-10-14T11:35:28Z</dc:date>
    </item>
    <item>
      <title>Re: Create new column with formula saved as a variable in a script</title>
      <link>https://community.jmp.com/t5/Discussions/Create-new-column-with-formula-saved-as-a-variable-in-a-script/m-p/556314#M77023</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2022 11:36:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-new-column-with-formula-saved-as-a-variable-in-a-script/m-p/556314#M77023</guid>
      <dc:creator>thedellette</dc:creator>
      <dc:date>2022-10-14T11:36:17Z</dc:date>
    </item>
  </channel>
</rss>

