<?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 Create new columns by loop formula calculation with specific column names in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Create-new-columns-by-loop-formula-calculation-with-specific/m-p/676244#M86294</link>
    <description>&lt;P&gt;Hello dear jmp experts/users,&lt;/P&gt;&lt;P&gt;I have a fixed format data table with similar column name formats like this (always similar two column name distinguished by _1):&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NAME, C1, P2 ... C1_1, P2_1 .... (actually many columns with this naming rule)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to create new columns with below formula: for exampe,&lt;/P&gt;&lt;P&gt;C1_cal by : C1-C1_1&lt;/P&gt;&lt;P&gt;P2_cal by : P2-P2_1&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;how do i use JSL to achieve loop for this? Thanks a lot!&lt;/P&gt;</description>
    <pubDate>Mon, 11 Sep 2023 06:31:33 GMT</pubDate>
    <dc:creator>MarkovRootFox46</dc:creator>
    <dc:date>2023-09-11T06:31:33Z</dc:date>
    <item>
      <title>Create new columns by loop formula calculation with specific column names</title>
      <link>https://community.jmp.com/t5/Discussions/Create-new-columns-by-loop-formula-calculation-with-specific/m-p/676244#M86294</link>
      <description>&lt;P&gt;Hello dear jmp experts/users,&lt;/P&gt;&lt;P&gt;I have a fixed format data table with similar column name formats like this (always similar two column name distinguished by _1):&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NAME, C1, P2 ... C1_1, P2_1 .... (actually many columns with this naming rule)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to create new columns with below formula: for exampe,&lt;/P&gt;&lt;P&gt;C1_cal by : C1-C1_1&lt;/P&gt;&lt;P&gt;P2_cal by : P2-P2_1&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;how do i use JSL to achieve loop for this? Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2023 06:31:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-new-columns-by-loop-formula-calculation-with-specific/m-p/676244#M86294</guid>
      <dc:creator>MarkovRootFox46</dc:creator>
      <dc:date>2023-09-11T06:31:33Z</dc:date>
    </item>
    <item>
      <title>Re: Create new columns by loop formula calculation with specific column names</title>
      <link>https://community.jmp.com/t5/Discussions/Create-new-columns-by-loop-formula-calculation-with-specific/m-p/676257#M86295</link>
      <description>&lt;P&gt;Quite a lot of assumptions made regarding column names and column ordering&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(1),
	Compress File When Saved(1),
	New Column("Name", Character, "Nominal", Set Values({})),
	New Column("Column1", Numeric, "Continuous", Format("Best", 12), Set Values([1])),
	New Column("Column2", Numeric, "Continuous", Format("Best", 12), Set Values([2])),
	New Column("Column1_1", Numeric, "Continuous", Format("Best", 12), Set Values([2])),
	New Column("Column2_1", Numeric, "Continuous", Format("Best", 12), Set Values([4]))
);

all_colnames = dt &amp;lt;&amp;lt; Get Column Names("String");
Remove From(all_colnames, 1); // Drop first column

For Each({col_name}, all_colnames[1::(N Items(all_colnames)/2)],
	Eval(Substitute(
		Expr(
			dt &amp;lt;&amp;lt; New Column(col_name|| "_cal", Numeric, Continuous, Formula(
				_firstcol_ - _secondcol_
			));
		),
		Expr(_firstcol_), Name Expr(AsColumn(col_name)),
		Expr(_secondcol_), Name Expr(AsColumn(col_name || "_1"))
	));
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Scripting Index and Scripting Guide have good information regarding JMP Scripting.&amp;nbsp;&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;&amp;nbsp;is good post regarding how to build formulas from variables&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2023 06:56:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-new-columns-by-loop-formula-calculation-with-specific/m-p/676257#M86295</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-09-11T06:56:19Z</dc:date>
    </item>
    <item>
      <title>Re: Create new columns by loop formula calculation with specific column names</title>
      <link>https://community.jmp.com/t5/Discussions/Create-new-columns-by-loop-formula-calculation-with-specific/m-p/676273#M86296</link>
      <description>&lt;P&gt;Thanks a lot!!!&lt;/P&gt;&lt;P&gt;if I'd like to change formular to&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;C1-3.5*C1_1:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;should i change the code to below format?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;_firstcol_ - 3.5*(_secondcol_)&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2023 08:04:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-new-columns-by-loop-formula-calculation-with-specific/m-p/676273#M86296</guid>
      <dc:creator>MarkovRootFox46</dc:creator>
      <dc:date>2023-09-11T08:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: Create new columns by loop formula calculation with specific column names</title>
      <link>https://community.jmp.com/t5/Discussions/Create-new-columns-by-loop-formula-calculation-with-specific/m-p/676285#M86297</link>
      <description>&lt;P&gt;Just try it and check the results and formula column property&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1694426154482.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/56455i92A0BFBDA0292D8C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1694426154482.png" alt="jthi_0-1694426154482.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2023 09:56:00 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-new-columns-by-loop-formula-calculation-with-specific/m-p/676285#M86297</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-09-11T09:56:00Z</dc:date>
    </item>
  </channel>
</rss>

