<?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: Using variables in column formulas in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Using-variables-in-column-formulas/m-p/687020#M87260</link>
    <description>&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; is good post regarding this. &amp;lt;&amp;lt; Get Selected Columns() does return a list of columns, so you might have to take that into account somehow (not sure why Column(cols) works, but I would suggest changing it to Column(cols[1])).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;P&gt;Here is one example what you could do. If you have any questions, please ask!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

dt &amp;lt;&amp;lt; Select Columns({"height", "weight"});

sel_cols = dt &amp;lt;&amp;lt; get selected columns("String");


Eval(EvalExpr(
	dt &amp;lt;&amp;lt; New Column("Mean " ||sel_cols[1], Numeric, Continuous, Formula(
		Mean(Expr(NameExpr(AsColumn(dt, sel_cols[1])))[1::20])
	));
));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-jsl"&gt;&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1697211500658.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/57601iE0FE046589E0168E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1697211500658.png" alt="jthi_0-1697211500658.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 13 Oct 2023 15:38:58 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2023-10-13T15:38:58Z</dc:date>
    <item>
      <title>Using variables in column formulas</title>
      <link>https://community.jmp.com/t5/Discussions/Using-variables-in-column-formulas/m-p/687004#M87259</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="CriticalMarten1_0-1697208584578.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/57596i10B5CD105C36EBB3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="CriticalMarten1_0-1697208584578.png" alt="CriticalMarten1_0-1697208584578.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I want to change all references to "AGC EXP101P 2" to the variable 'colname' so that when I run the script this code applies to the selected column in the data table and not just the column "AGC EXP101P 2". However, when I try to change it, JMP always reads the variable name as a string in the column formula and doesn't evaluate properly. How do I fix this so that the column formula recognises the variable?&lt;BR /&gt;&lt;BR /&gt;Thanks :)&lt;/img&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2023 14:59:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Using-variables-in-column-formulas/m-p/687004#M87259</guid>
      <dc:creator>CriticalMarten1</dc:creator>
      <dc:date>2023-10-13T14:59:11Z</dc:date>
    </item>
    <item>
      <title>Re: Using variables in column formulas</title>
      <link>https://community.jmp.com/t5/Discussions/Using-variables-in-column-formulas/m-p/687020#M87260</link>
      <description>&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; is good post regarding this. &amp;lt;&amp;lt; Get Selected Columns() does return a list of columns, so you might have to take that into account somehow (not sure why Column(cols) works, but I would suggest changing it to Column(cols[1])).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;P&gt;Here is one example what you could do. If you have any questions, please ask!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

dt &amp;lt;&amp;lt; Select Columns({"height", "weight"});

sel_cols = dt &amp;lt;&amp;lt; get selected columns("String");


Eval(EvalExpr(
	dt &amp;lt;&amp;lt; New Column("Mean " ||sel_cols[1], Numeric, Continuous, Formula(
		Mean(Expr(NameExpr(AsColumn(dt, sel_cols[1])))[1::20])
	));
));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-jsl"&gt;&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1697211500658.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/57601iE0FE046589E0168E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1697211500658.png" alt="jthi_0-1697211500658.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2023 15:38:58 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Using-variables-in-column-formulas/m-p/687020#M87260</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-10-13T15:38:58Z</dc:date>
    </item>
  </channel>
</rss>

