<?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: Creating new columns with a For loop and giving each column its own name and formula in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Creating-new-columns-with-a-For-loop-and-giving-each-column-its/m-p/49242#M27992</link>
    <description>&lt;P&gt;How timely, check out 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="_self"&gt;JSL Cookbook article &lt;/A&gt;which does something very similar.&amp;nbsp; Just specify your own list of columns to change, then modify the new column name and formula.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I suggest selecting the columns and using the Current Data Table() &amp;lt;&amp;lt; Get Selected Columns message to write the list to the log, which you can then copy and paste into your code.&lt;/P&gt;</description>
    <pubDate>Thu, 04 Jan 2018 17:24:43 GMT</pubDate>
    <dc:creator>ih</dc:creator>
    <dc:date>2018-01-04T17:24:43Z</dc:date>
    <item>
      <title>Creating new columns with a For loop and giving each column its own name and formula</title>
      <link>https://community.jmp.com/t5/Discussions/Creating-new-columns-with-a-For-loop-and-giving-each-column-its/m-p/49235#M27990</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a large data table with values and column headers test1,test2,test3,test4,...,test800. Some of these values are negative, and I would like to take all the columns I define in the list "Datalist_log_2" and create a new column called "test1_pos" with the absolute values. (For each test).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Datalist_log_2 = {test1, test2, test5, test319};
wmax = N Items( Datalist_log_2 );

For ( w = 1, w &amp;lt;=wmax, w++,
	Temp12 = Char(Datalist_log_2[w]);
	NewColName = Temp12||"_pos";	//not sure if I need to do this extra round, but it works. Will figure that out myself.
	NewColumn(NewColName, Numeric, Continuous, Formula(Abs(Datalist_log_2[w]))) 
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem seems to be that the Formula() is trying to build the absolute value of the variable "test1" in the first iteration, but of course I don't want sqrt(test1*test1). Instead I would like the newly created column to get the absolute values of the reference column&amp;nbsp;with the name&amp;nbsp;"test1".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot for your help&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 16:26:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Creating-new-columns-with-a-For-loop-and-giving-each-column-its/m-p/49235#M27990</guid>
      <dc:creator>PS</dc:creator>
      <dc:date>2018-01-04T16:26:35Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new columns with a For loop and giving each column its own name and formula</title>
      <link>https://community.jmp.com/t5/Discussions/Creating-new-columns-with-a-For-loop-and-giving-each-column-its/m-p/49242#M27992</link>
      <description>&lt;P&gt;How timely, check out 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="_self"&gt;JSL Cookbook article &lt;/A&gt;which does something very similar.&amp;nbsp; Just specify your own list of columns to change, then modify the new column name and formula.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I suggest selecting the columns and using the Current Data Table() &amp;lt;&amp;lt; Get Selected Columns message to write the list to the log, which you can then copy and paste into your code.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 17:24:43 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Creating-new-columns-with-a-For-loop-and-giving-each-column-its/m-p/49242#M27992</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2018-01-04T17:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new columns with a For loop and giving each column its own name and formula</title>
      <link>https://community.jmp.com/t5/Discussions/Creating-new-columns-with-a-For-loop-and-giving-each-column-its/m-p/49245#M27994</link>
      <description>&lt;P&gt;Below is a modification of your current code, using the same methodology as I passed to you in your previous post "&lt;EM&gt;Combining For loop and Dispatch() command in a variability chart"&amp;nbsp;&lt;/EM&gt;.&amp;nbsp; If you are not able to interpret what is going on, I suggest that you take a look in the Scripting Guide for explanation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Help==&amp;gt;Books==&amp;gt;Scripting Guide&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Datalist_log_2 = {test1, test2, test3};

For( w = 1, w &amp;lt;= N Items( Datalist_log_2 ), w++,
	Eval(
		Substitute(
				Expr(
					New Column( Char( Datalist_log_2[w] ) || "_pos",
						Numeric,
						Continuous,
						Formula( Abs( __Col__ ) )
					)
				),
			Expr( __col__ ), Parse( ":" || Char( Datalist_log_2[w] ) )
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Jan 2018 17:59:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Creating-new-columns-with-a-For-loop-and-giving-each-column-its/m-p/49245#M27994</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2018-01-04T17:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new columns with a For loop and giving each column its own name and formula</title>
      <link>https://community.jmp.com/t5/Discussions/Creating-new-columns-with-a-For-loop-and-giving-each-column-its/m-p/49287#M28017</link>
      <description>&lt;P&gt;This works great, thanks&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2018 08:37:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Creating-new-columns-with-a-For-loop-and-giving-each-column-its/m-p/49287#M28017</guid>
      <dc:creator>PS</dc:creator>
      <dc:date>2018-01-05T08:37:32Z</dc:date>
    </item>
  </channel>
</rss>

