<?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: Need help with expressions, column references, formulas and column renaming in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Need-help-with-expressions-column-references-formulas-and-column/m-p/489344#M73246</link>
    <description>&lt;P&gt;I see one way of doing that (but rather not do it this way).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Get column names not as strings, but as references, and then just use &lt;EM&gt;Name Expr()&lt;/EM&gt;:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;oldCol = (dt &amp;lt;&amp;lt; Get Column Names())[1];&lt;BR /&gt;Eval( Eval Expr( dt &amp;lt;&amp;lt; New Column( "NewColumn", formula( Name Expr( oldCol ) ) ) ) );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but I already have name of the column as a string, and would like to stick with it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 20 May 2022 20:46:56 GMT</pubDate>
    <dc:creator>miguello</dc:creator>
    <dc:date>2022-05-20T20:46:56Z</dc:date>
    <item>
      <title>Need help with expressions, column references, formulas and column renaming</title>
      <link>https://community.jmp.com/t5/Discussions/Need-help-with-expressions-column-references-formulas-and-column/m-p/489323#M73245</link>
      <description>&lt;P&gt;All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Need some help in the following case.&lt;/P&gt;&lt;P&gt;I have a name of a column in a string format.&lt;/P&gt;&lt;P&gt;I need to create a new column with formula based on the old one. I do it like so:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;oldCol = "OldColumn";
Eval( Eval Expr( dt &amp;lt;&amp;lt; New Column( "NewColumn", formula( As Column( Expr( oldCol ) ) ) ) ) );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Then later in the script I need to rename the old column. I do it like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Column(oldCol) &amp;lt;&amp;lt; Set Name("NewOldColumn");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The problem now is that since I have the New Column's formula in the form of:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;As Column("OldColumn")&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;it does not update when OldColumn changes name.&lt;/P&gt;&lt;P&gt;I would like to have it in the form of&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;:OldColumn&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but I don't know how to do that.&lt;/P&gt;&lt;P&gt;So, the question is: How do I need to modify expression:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Eval( Eval Expr( dt &amp;lt;&amp;lt; New Column( "NewColumn", formula( As Column( Expr( oldCol ) ) ) ) ) );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;so that it produces formula in the form of &lt;EM&gt;:OldColumn&lt;/EM&gt;, and not in the form of &lt;EM&gt;As Column("OldColumn")&lt;/EM&gt;?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the full script to play with:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = New Table( "TestColumnsReferences",
	Add Rows( 3 ),
	New Column( "OldColumn", Character, "Nominal", Set Values( {"a", "b", "c"} ) )
);
oldCol = (dt &amp;lt;&amp;lt; Get Column Names(string))[1];
//oldCol = "OldColumn";
Eval( Eval Expr( dt &amp;lt;&amp;lt; New Column( "NewColumn", formula( As Column( Expr( oldCol ) ) ) ) ) );
Column(oldCol) &amp;lt;&amp;lt; Set Name("NewOldColumn");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks, M.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 16:59:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Need-help-with-expressions-column-references-formulas-and-column/m-p/489323#M73245</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2023-06-09T16:59:44Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with expressions, column references, formulas and column renaming</title>
      <link>https://community.jmp.com/t5/Discussions/Need-help-with-expressions-column-references-formulas-and-column/m-p/489344#M73246</link>
      <description>&lt;P&gt;I see one way of doing that (but rather not do it this way).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Get column names not as strings, but as references, and then just use &lt;EM&gt;Name Expr()&lt;/EM&gt;:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;oldCol = (dt &amp;lt;&amp;lt; Get Column Names())[1];&lt;BR /&gt;Eval( Eval Expr( dt &amp;lt;&amp;lt; New Column( "NewColumn", formula( Name Expr( oldCol ) ) ) ) );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but I already have name of the column as a string, and would like to stick with it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2022 20:46:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Need-help-with-expressions-column-references-formulas-and-column/m-p/489344#M73246</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2022-05-20T20:46:56Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with expressions, column references, formulas and column renaming</title>
      <link>https://community.jmp.com/t5/Discussions/Need-help-with-expressions-column-references-formulas-and-column/m-p/489375#M73249</link>
      <description>&lt;P&gt;Here is one approach that works for me.&amp;nbsp; I have expanded the naming to handle complex JMP column names.&amp;nbsp; This confuses the reader a bit, but makes the method more powerful&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = New Table( "TestColumnsReferences",
	Add Rows( 3 ),
	New Column( "OldColumn+one", Character, "Nominal", Set Values( {"a", "b", "c"} ) )
);
oldCol = (dt &amp;lt;&amp;lt; Get Column Names( string ))[1];
//oldCol = "OldColumn";
//Eval( Eval Expr( dt &amp;lt;&amp;lt; New Column( "NewColumn", formula( As Column( Expr( oldCol ) ) ) ) ) );
Eval(
	Substitute(
			Expr(
				dt &amp;lt;&amp;lt; New Column( "NewColumn", formula( __oldCol__ ) )
			),
		Expr( __oldCol__ ), parse(":\!"" || oldCol || "\!"n")
	)
);
Column( oldCol ) &amp;lt;&amp;lt; Set Name( "NewOldColumn" );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2022 22:08:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Need-help-with-expressions-column-references-formulas-and-column/m-p/489375#M73249</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2022-05-20T22:08:06Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with expressions, column references, formulas and column renaming</title>
      <link>https://community.jmp.com/t5/Discussions/Need-help-with-expressions-column-references-formulas-and-column/m-p/489379#M73251</link>
      <description>&lt;P&gt;Ok, I figured it out. For the formula part just use the following chain:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt; Name Expr(Expr(Parse(Eval Insert(":#oldCol#", startChar="#"))))&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Had to use startChar="#" since in real script formula actually uses REgEx where "^" is used.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the full script is this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = New Table( "TestColumnsReferences",
	Add Rows( 3 ),
	New Column( "OldColumn", Character, "Nominal", Set Values( {"a", "b", "c"} ) )
);
oldCol = (dt &amp;lt;&amp;lt; Get Column Names(string))[1];
//oldCol = "OldColumn";
Eval( Eval Expr( dt &amp;lt;&amp;lt; New Column( "NewColumn", formula( Name Expr(Expr(Parse(Eval Insert(":#oldCol#", startChar="#")))) ) ) ) );
Column(oldCol) &amp;lt;&amp;lt; Set Name("NewOldColumn");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This way formula has &lt;EM&gt;:OldColumn&lt;/EM&gt; rather than &lt;EM&gt;As Column("OldColumn")&lt;/EM&gt; and you can now safely rename columns without breaking formula.&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2022 22:14:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Need-help-with-expressions-column-references-formulas-and-column/m-p/489379#M73251</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2022-05-20T22:14:49Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with expressions, column references, formulas and column renaming</title>
      <link>https://community.jmp.com/t5/Discussions/Need-help-with-expressions-column-references-formulas-and-column/m-p/489384#M73252</link>
      <description>&lt;P&gt;Yep, essentially the same approach as I showed below, only use &lt;EM&gt;Substitute&lt;/EM&gt; instead of &lt;EM&gt;Eval Insert&lt;/EM&gt;, right?&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2022 22:17:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Need-help-with-expressions-column-references-formulas-and-column/m-p/489384#M73252</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2022-05-20T22:17:41Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with expressions, column references, formulas and column renaming</title>
      <link>https://community.jmp.com/t5/Discussions/Need-help-with-expressions-column-references-formulas-and-column/m-p/489403#M73255</link>
      <description>&lt;P&gt;Personally I like using the &lt;CODE class=" language-jsl"&gt;JSL Quote()&lt;/CODE&gt; function to maintain syntax highlighting and lexical parsing -- then just pass the value into the &lt;CODE class=" language-jsl"&gt;:Name()&lt;/CODE&gt; directive, as such&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = New Table( "TestColumnsReferences",
	Add Rows( 3 ),
	New Column( "OldColumn", Character, "Nominal", Set Values( {"a", "b", "c"} ) )
);
oldCol = (dt &amp;lt;&amp;lt; Get Column Names(string))[1];
//oldCol = "OldColumn";
Eval( Parse( Eval Insert( JSL Quote(
	dt &amp;lt;&amp;lt; New Column( "NewColumn", Formula( :Name("^oldCol^") ) )
) ) ) );
Column(oldCol) &amp;lt;&amp;lt; Set Name("NewOldColumn");&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 21 May 2022 01:08:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Need-help-with-expressions-column-references-formulas-and-column/m-p/489403#M73255</guid>
      <dc:creator>ErraticAttack</dc:creator>
      <dc:date>2022-05-21T01:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with expressions, column references, formulas and column renaming</title>
      <link>https://community.jmp.com/t5/Discussions/Need-help-with-expressions-column-references-formulas-and-column/m-p/490220#M73282</link>
      <description>&lt;P&gt;One more option is combination of Eval(), EvalExpr(), Expr(), Name Expr() and As Column()&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = New Table("TestColumnsReferences", Add Rows(3), 
	New Column("OldColumn", Character, "Nominal", Set Values({"a", "b", "c"}))		
);

oldCol = (dt &amp;lt;&amp;lt; Get Column Names(string))[1];

//oldCol = "OldColumn";
Eval(Eval Expr(dt &amp;lt;&amp;lt; New Column("NewColumn", formula(Expr(Name Expr(AsColumn(oldCol)))))));
Column(oldCol) &amp;lt;&amp;lt; Set Name("NewOldColumn");&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 May 2022 13:57:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Need-help-with-expressions-column-references-formulas-and-column/m-p/490220#M73282</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-05-23T13:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with expressions, column references, formulas and column renaming</title>
      <link>https://community.jmp.com/t5/Discussions/Need-help-with-expressions-column-references-formulas-and-column/m-p/490905#M73288</link>
      <description>&lt;P&gt;&lt;STRIKE&gt;Problem with "As Column" as I explained in the question is that is stays in the formula, and then when I later change name of the column that I refer to in the column (and I do change it) the formula becomes invalid&lt;/STRIKE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My apologies, with your combination Expr --&amp;gt; Name Expr --&amp;gt; As Column it does work! It turns As Column("string") into :string!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been given several solutions here, and I really liked the one with JSL Quote, but this is my new favorite. Will have to re-do the script all over again :)&lt;/img&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 May 2022 23:22:34 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Need-help-with-expressions-column-references-formulas-and-column/m-p/490905#M73288</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2022-05-23T23:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with expressions, column references, formulas and column renaming</title>
      <link>https://community.jmp.com/t5/Discussions/Need-help-with-expressions-column-references-formulas-and-column/m-p/490913#M73289</link>
      <description>&lt;P&gt;Thank you for the tip on JSL Quote()! It really is much cleaner now that I don't have to escape all the quotes.&lt;/P&gt;</description>
      <pubDate>Mon, 23 May 2022 23:14:57 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Need-help-with-expressions-column-references-formulas-and-column/m-p/490913#M73289</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2022-05-23T23:14:57Z</dc:date>
    </item>
  </channel>
</rss>

