<?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 Use selected column for formula in a new column in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Use-selected-column-for-formula-in-a-new-column/m-p/35399#M20893</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;i try to genrate a script where i have to select a column . With this selection&amp;nbsp;I create a new column, which contains a formula (with the selcted column). Here is my approach:&lt;/P&gt;&lt;PRE&gt;dt = Current Data Table ();
dt &amp;lt;&amp;lt; New Table Variable( "Range", 2 );

New Window( "Select Column",
lb = Col List Box( all ), dt &amp;lt;&amp;lt; New Table Variable( "Selected Column", lb &amp;lt;&amp;lt;get selected ),
Button Box( "Moving Average", dt &amp;lt;&amp;lt;New Column ("Movin Average", Numeric, Formula (:Range + "selected Column") )
));&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two Problems:&lt;/P&gt;&lt;P&gt;1. How can I genrate a Coulumn Variable by the selection?&lt;/P&gt;&lt;P&gt;2. How can&amp;nbsp;I use this&amp;nbsp;Variable in my formula? For "Range" (numeric) it is possible, but for the selected column (character) not.&lt;/P&gt;</description>
    <pubDate>Tue, 07 Feb 2017 09:43:23 GMT</pubDate>
    <dc:creator>mkennke</dc:creator>
    <dc:date>2017-02-07T09:43:23Z</dc:date>
    <item>
      <title>Use selected column for formula in a new column</title>
      <link>https://community.jmp.com/t5/Discussions/Use-selected-column-for-formula-in-a-new-column/m-p/35399#M20893</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;i try to genrate a script where i have to select a column . With this selection&amp;nbsp;I create a new column, which contains a formula (with the selcted column). Here is my approach:&lt;/P&gt;&lt;PRE&gt;dt = Current Data Table ();
dt &amp;lt;&amp;lt; New Table Variable( "Range", 2 );

New Window( "Select Column",
lb = Col List Box( all ), dt &amp;lt;&amp;lt; New Table Variable( "Selected Column", lb &amp;lt;&amp;lt;get selected ),
Button Box( "Moving Average", dt &amp;lt;&amp;lt;New Column ("Movin Average", Numeric, Formula (:Range + "selected Column") )
));&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two Problems:&lt;/P&gt;&lt;P&gt;1. How can I genrate a Coulumn Variable by the selection?&lt;/P&gt;&lt;P&gt;2. How can&amp;nbsp;I use this&amp;nbsp;Variable in my formula? For "Range" (numeric) it is possible, but for the selected column (character) not.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 09:43:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Use-selected-column-for-formula-in-a-new-column/m-p/35399#M20893</guid>
      <dc:creator>mkennke</dc:creator>
      <dc:date>2017-02-07T09:43:23Z</dc:date>
    </item>
    <item>
      <title>Re: Use selected column for formula in a new column</title>
      <link>https://community.jmp.com/t5/Discussions/Use-selected-column-for-formula-in-a-new-column/m-p/35437#M20901</link>
      <description>&lt;P&gt;Here is a working example of a script that will do what I believe your original script attempted to do.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( "$SAMPLE_DATA\big class.jmp" );
dt &amp;lt;&amp;lt; New Table Variable( "Range", 2 );

New Window( "Select Column",
	lb = Col List Box(
		Data Table( dt &amp;lt;&amp;lt; get name ),
		all,
		min col( 1 ),
		max col( 1 ),
		dt &amp;lt;&amp;lt; New Table Variable( "Selected Column", (lb &amp;lt;&amp;lt; get selected )[1])
	),
	Button Box( "Moving Average",
		Eval(
			Substitute(
					Expr(
						dt &amp;lt;&amp;lt; New Column( "Movin Average", Numeric, Formula( __formula__ ) )
					),
				Expr( __formula__ ), Parse( dt &amp;lt;&amp;lt; get table variable( "Range" ) || " + :" || (lb &amp;lt;&amp;lt; get selected)[1] )
			)
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now the issue I am having is to under stand a couple of items.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Why are you creating Table Variables for the value of Range and the name of the new Column?&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;Is the formula you specified actually what you want?&amp;nbsp; Adding the number 2 to the value of another column, isn't giving any kind of Moving Average.&amp;nbsp; Is what you really want to do, to create a true moving average of the current row, and the previous values from the last 2 rows?&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Tue, 07 Feb 2017 16:15:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Use-selected-column-for-formula-in-a-new-column/m-p/35437#M20901</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2017-02-07T16:15:49Z</dc:date>
    </item>
    <item>
      <title>Re: Use selected column for formula in a new column</title>
      <link>https://community.jmp.com/t5/Discussions/Use-selected-column-for-formula-in-a-new-column/m-p/35440#M20904</link>
      <description>&lt;P&gt;Thank You!&lt;/P&gt;&lt;P&gt;If I look to the code it should be exactly what I'm looking for. But i got an error message:&lt;/P&gt;&lt;P&gt;argument should be character in access or evaluation of 'Concat' , Bad Argument( (lb &amp;lt;&amp;lt; get selected)[1] ), dt &amp;lt;&amp;lt; get table variable( "Range" ) ||&amp;nbsp; /*###*/" + :" ||&amp;nbsp; /*###*/(lb &amp;lt;&amp;lt; get selected&lt;BR /&gt;)[1] /*###*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As Table variable&amp;nbsp;I got the selcted column. But the evaluation of the formula for the new column is not possible.&lt;/P&gt;&lt;P&gt;Do I have to change any Preferences in my JMP Version?&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 16:30:57 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Use-selected-column-for-formula-in-a-new-column/m-p/35440#M20904</guid>
      <dc:creator>mkennke</dc:creator>
      <dc:date>2017-02-07T16:30:57Z</dc:date>
    </item>
    <item>
      <title>Re: Use selected column for formula in a new column</title>
      <link>https://community.jmp.com/t5/Discussions/Use-selected-column-for-formula-in-a-new-column/m-p/35448#M20911</link>
      <description>&lt;P&gt;The code is complaining that the value of Range isn't a character string.&amp;nbsp; So to correct that, the below code forces both the value of range, and the column name returned to be character strings, by using the char() function to insure that they are character strings.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( "$SAMPLE_DATA\big class.jmp" );
dt &amp;lt;&amp;lt; New Table Variable( "Range", 2 );

New Window( "Select Column",
	lb = Col List Box(
		Data Table( dt &amp;lt;&amp;lt; get name ),
		all,
		min col( 1 ),
		max col( 1 ),
		dt &amp;lt;&amp;lt; New Table Variable( "Selected Column", (lb &amp;lt;&amp;lt; get selected )[1])
	),
	Button Box( "Moving Average",
		Eval(
			Substitute(
					Expr(
						dt &amp;lt;&amp;lt; New Column( "Movin Average", Numeric, Formula( __formula__ ) )
					),
				Expr( __formula__ ), Parse( char(dt &amp;lt;&amp;lt; get table variable( "Range" )) || " + :" || char((lb &amp;lt;&amp;lt; get selected)[1]) )
			)
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Feb 2017 17:15:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Use-selected-column-for-formula-in-a-new-column/m-p/35448#M20911</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2017-02-07T17:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: Use selected column for formula in a new column</title>
      <link>https://community.jmp.com/t5/Discussions/Use-selected-column-for-formula-in-a-new-column/m-p/35488#M20937</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 10:09:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Use-selected-column-for-formula-in-a-new-column/m-p/35488#M20937</guid>
      <dc:creator>mkennke</dc:creator>
      <dc:date>2017-02-08T10:09:45Z</dc:date>
    </item>
    <item>
      <title>Re: Use selected column for formula in a new column</title>
      <link>https://community.jmp.com/t5/Discussions/Use-selected-column-for-formula-in-a-new-column/m-p/87677#M38684</link>
      <description>&lt;P&gt;High Jim, this is a great script.&amp;nbsp; Is it possible to create additional Formula&amp;nbsp;columns (Col Mean() ...) by adding additional formula buttons?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jan 2019 16:30:34 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Use-selected-column-for-formula-in-a-new-column/m-p/87677#M38684</guid>
      <dc:creator>Thomas1</dc:creator>
      <dc:date>2019-01-03T16:30:34Z</dc:date>
    </item>
  </channel>
</rss>

