<?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: Column name from string in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Column-name-from-string/m-p/393057#M64338</link>
    <description>&lt;P&gt;Take a look at this &lt;A href="https://community.jmp.com/t5/JSL-Cookbook/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/ta-p/48998" target="_blank" rel="noopener"&gt;Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( "$SAMPLE_DATA/Cities.jmp" );
//example column
dt &amp;lt;&amp;lt; New Column("klaatu barada nikto", formula(3));
//suppose we don't know what exactly will be in 'a' as it is controlled by a for loop etc.
a = Concat Items( {"klaatu", "barada", "nikto"}, " " );

//can we get another column to take 'a' as an input?

Eval(EvalExpr(dt &amp;lt;&amp;lt; New Column("Gort", numeric, formula(ascolumn(expr(a))*:Y))));&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 14 Jun 2021 08:53:40 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2021-06-14T08:53:40Z</dc:date>
    <item>
      <title>Column name from string</title>
      <link>https://community.jmp.com/t5/Discussions/Column-name-from-string/m-p/393036#M64336</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;I am working on a script that I would like to use a string as a column name, and use that column name in a formula, see below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( "$SAMPLE_DATA/Cities.jmp" );
//example column
dt &amp;lt;&amp;lt; New Column("klaatu barada nikto", formula(3));
//suppose we don't know what exactly will be in 'a' as it is controlled by a for loop etc.
a = Concat Items( {"klaatu", "barada", "nikto"}, " " );

//can we get another column to take 'a' as an input?
dt &amp;lt;&amp;lt; New Column("Gort", formula(column(a)*:Y));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When I use this however, it does not see "klaatu barada nikto" as a valid column, even though we created it before.&lt;/P&gt;&lt;P&gt;From other posts I have seen that the column() function can be used to assign a string to a column and I have used it in this way before, but in this instance it does not work. All we end up with is this:&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="help.png" style="width: 153px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/33510i7DA2159FD2CE06D2/image-size/large?v=v2&amp;amp;px=999" role="button" title="help.png" alt="help.png" /&gt;&lt;/span&gt;&lt;BR /&gt;Does anyone know a workaround for this? Thanks for any help in advance!&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:31:47 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Column-name-from-string/m-p/393036#M64336</guid>
      <dc:creator>rjack</dc:creator>
      <dc:date>2023-06-10T23:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: Column name from string</title>
      <link>https://community.jmp.com/t5/Discussions/Column-name-from-string/m-p/393057#M64338</link>
      <description>&lt;P&gt;Take a look at this &lt;A href="https://community.jmp.com/t5/JSL-Cookbook/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/ta-p/48998" target="_blank" rel="noopener"&gt;Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( "$SAMPLE_DATA/Cities.jmp" );
//example column
dt &amp;lt;&amp;lt; New Column("klaatu barada nikto", formula(3));
//suppose we don't know what exactly will be in 'a' as it is controlled by a for loop etc.
a = Concat Items( {"klaatu", "barada", "nikto"}, " " );

//can we get another column to take 'a' as an input?

Eval(EvalExpr(dt &amp;lt;&amp;lt; New Column("Gort", numeric, formula(ascolumn(expr(a))*:Y))));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Jun 2021 08:53:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Column-name-from-string/m-p/393057#M64338</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-06-14T08:53:40Z</dc:date>
    </item>
    <item>
      <title>Re: Column name from string</title>
      <link>https://community.jmp.com/t5/Discussions/Column-name-from-string/m-p/393062#M64339</link>
      <description>&lt;P&gt;Fantastic! Thank you so much for your help.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Jun 2021 08:55:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Column-name-from-string/m-p/393062#M64339</guid>
      <dc:creator>rjack</dc:creator>
      <dc:date>2021-06-14T08:55:55Z</dc:date>
    </item>
    <item>
      <title>Re: Column name from string</title>
      <link>https://community.jmp.com/t5/Discussions/Column-name-from-string/m-p/489362#M73248</link>
      <description>&lt;P&gt;Jarmo,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using the same approach in one of my scripts and bumped into a problem: the formula in the new column will have that "a" column as this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Formula(As Column("klaatu barada nikto")*:Y)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;which means that if name of that column changes (and in my case it changes) this formula will become invalid. I need to somehow reference it not as &lt;EM&gt;As Column("name")&lt;/EM&gt; but as &lt;EM&gt;:name&lt;/EM&gt; - any way to do that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&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 21:18:29 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Column-name-from-string/m-p/489362#M73248</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2022-05-20T21:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: Column name from string</title>
      <link>https://community.jmp.com/t5/Discussions/Column-name-from-string/m-p/489737#M73269</link>
      <description>&lt;P&gt;If I understand correctly what you want, you could try adding Name Expr&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open( "$SAMPLE_DATA/Cities.jmp" );
//example column
dt &amp;lt;&amp;lt; New Column("klaatu barada nikto", formula(3));
//suppose we don't know what exactly will be in 'a' as it is controlled by a for loop etc.
a = Concat Items( {"klaatu", "barada", "nikto"}, " " );

Eval(EvalExpr(dt &amp;lt;&amp;lt; New Column("Gort", numeric, formula(Expr(Name Expr(As Column(a)))*:Y))));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1653236614827.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/42624iB81E7CFCBEDD76B4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1653236614827.png" alt="jthi_0-1653236614827.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 22 May 2022 16:23:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Column-name-from-string/m-p/489737#M73269</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-05-22T16:23:56Z</dc:date>
    </item>
  </channel>
</rss>

