<?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: Script to convert a string from a list into the body of a formula in new column. in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Script-to-convert-a-string-from-a-list-into-the-body-of-a/m-p/626113#M82485</link>
    <description>&lt;P&gt;Outstanding. Did the trick. Thanks a lot.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 25 Apr 2023 23:27:19 GMT</pubDate>
    <dc:creator>Sburel</dc:creator>
    <dc:date>2023-04-25T23:27:19Z</dc:date>
    <item>
      <title>Script to convert a string from a list into the body of a formula in new column.</title>
      <link>https://community.jmp.com/t5/Discussions/Script-to-convert-a-string-from-a-list-into-the-body-of-a/m-p/626006#M82470</link>
      <description>&lt;P&gt;Following the process of identifying some interacting columns after using the fit platform and looking for some interaction (factorial...). I want to use the resulting term (such as&amp;nbsp;cA*0.1+cB*0.3) from the interaction as the starting point to automatically create column formulas from those terms. I struggling to find a way to use the content of a string such as"cA*0.1+cB*0.3" where cA and cB represent the names of 2 columns present in a table to build new formulas.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The last portion of the script create the formula but is just representing the content of the string instead of evaluating its content.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestion would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sebastien&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);
clear log();

dtinit=Open( "$SAMPLE_DATA/Bands Data.jmp" );

// Make TableBox into a Data Table
// → Data Table( "Untitled 3" )
//terms tables resulting from a generalized regression taking into consideration term interaction.

dtfeat = New Table( "features",
	Add Rows( 14 ),
	New Column( "Term",
		Character,
		"Nominal",
		Set Property( "ID Column", 1 ),
		Set Values(
			{"press speed", "(roller durometer-34.5151)*(anode space ratio-102.914)", "(proof cut-44.9671)*(blade pressure-30.8904)",
			"(anode space ratio-102.914)*(chrome content-99.6164)", "(humidity-78.6849)*(press speed-1851.21)", "roller durometer",
			"(roller durometer-34.5151)*(current density-39.0164)", "(humidity-78.6849)*(wax-2.4037)", "(wax-2.4037)*(chrome content-99.6164)",
			"(viscosity-50.7836)*(press speed-1851.21)", "(wax-2.4037)*(hardener-0.96014)", "(roughness-0.71969)*(current density-39.0164)",
			"(humidity-78.6849)*(ink pct-55.6473)", "(blade pressure-30.8904)*(press speed-1851.21)"}
		)
	),
	Set Label Columns( :Term )
);

//Identifies interacting terms
// New column: interaction
dtfeat &amp;lt;&amp;lt; New Column( "interaction", Character, "Nominal", Formula( If( Starts With( :term, "(" ), :term, "" ) ) ) &amp;lt;&amp;lt;
Move Selected Columns( {:interaction}, after( :term ) );



value = dtfeat:interaction &amp;lt;&amp;lt; get values();

uniqueinteraction = Associative Array( value ) &amp;lt;&amp;lt; get keys;
nvinteract = N Items( uniqueinteraction );
	
//Will create a column named after the interacting terms
//Should apply a formula based on the interacting terms	
//However, not sure how to extract the string from the list 'uniqueinteraction' so that is it not seen as a string but rather as 'formula instruction'	where some portion of the term is recognized as a column namealready present in the original table
For( i = 1, i &amp;lt;= nvinteract, i++,
	dtinit &amp;lt;&amp;lt; New Column( uniqueinteraction[i], Numeric, "Continuous", Format( "Best", 12 ), Formula( Eval( uniqueinteraction[i] ) )&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 16:08:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Script-to-convert-a-string-from-a-list-into-the-body-of-a/m-p/626006#M82470</guid>
      <dc:creator>Sburel</dc:creator>
      <dc:date>2023-06-09T16:08:49Z</dc:date>
    </item>
    <item>
      <title>Re: Script to convert a string from a list into the body of a formula in new column.</title>
      <link>https://community.jmp.com/t5/Discussions/Script-to-convert-a-string-from-a-list-into-the-body-of-a/m-p/626028#M82474</link>
      <description>&lt;P&gt;In this example all the "formulas" have column name starting after "(" so you could substitute that with "(:" and then use Parse&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dtinit = Open("$SAMPLE_DATA/Bands Data.jmp");

dtfeat = New Table("features",
	Add Rows(14),
	New Column("Term",
		Character,
		"Nominal",
		Set Property("ID Column", 1),
		Set Values(
			{"press speed", "(roller durometer-34.5151)*(anode space ratio-102.914)", "(proof cut-44.9671)*(blade pressure-30.8904)",
			"(anode space ratio-102.914)*(chrome content-99.6164)", "(humidity-78.6849)*(press speed-1851.21)", "roller durometer",
			"(roller durometer-34.5151)*(current density-39.0164)", "(humidity-78.6849)*(wax-2.4037)",
			"(wax-2.4037)*(chrome content-99.6164)", "(viscosity-50.7836)*(press speed-1851.21)", "(wax-2.4037)*(hardener-0.96014)",
			"(roughness-0.71969)*(current density-39.0164)", "(humidity-78.6849)*(ink pct-55.6473)",
			"(blade pressure-30.8904)*(press speed-1851.21)"}
		)
	),
	Set Label Columns(:Term)
);

dtfeat &amp;lt;&amp;lt; New Column("interaction", Character, "Nominal", Formula(If(Starts With(:term, "("), :term, ""))) &amp;lt;&amp;lt;
Move Selected Columns({:interaction}, after(:term));

value = dtfeat:interaction &amp;lt;&amp;lt; get values();

uniqueinteraction = Associative Array(value) &amp;lt;&amp;lt; get keys;

For Each({uniq}, uniqueinteraction,
	f_str = Substitute(uniq, "(", "(:");
	If(IsMissing(f_str),
		continue();
	);
	Eval(EvalExpr(
		dtinit &amp;lt;&amp;lt; New Column(uniq, Numeric, "Continuous", 
			Formula(Expr(Parse(f_str)))
	)));
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;LI-MESSAGE title="Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute" uid="48998" url="https://community.jmp.com/t5/JSL-Cookbook-Archived/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/m-p/48998#U48998" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-tkb-thread lia-fa-icon lia-fa-tkb lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2023 17:41:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Script-to-convert-a-string-from-a-list-into-the-body-of-a/m-p/626028#M82474</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-04-25T17:41:28Z</dc:date>
    </item>
    <item>
      <title>Re: Script to convert a string from a list into the body of a formula in new column.</title>
      <link>https://community.jmp.com/t5/Discussions/Script-to-convert-a-string-from-a-list-into-the-body-of-a/m-p/626113#M82485</link>
      <description>&lt;P&gt;Outstanding. Did the trick. Thanks a lot.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2023 23:27:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Script-to-convert-a-string-from-a-list-into-the-body-of-a/m-p/626113#M82485</guid>
      <dc:creator>Sburel</dc:creator>
      <dc:date>2023-04-25T23:27:19Z</dc:date>
    </item>
  </channel>
</rss>

