<?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: Subtraction of multiple column in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Script-to-do-Subtraction-of-multiple-column/m-p/426247#M67604</link>
    <description>&lt;P&gt;Hi Jim,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the input,&lt;/P&gt;&lt;P&gt;But column name is variable control and name can change based on run to run,&lt;/P&gt;&lt;P&gt;how to code in that situation ?&lt;/P&gt;</description>
    <pubDate>Thu, 14 Oct 2021 02:37:15 GMT</pubDate>
    <dc:creator>jinsejoseph</dc:creator>
    <dc:date>2021-10-14T02:37:15Z</dc:date>
    <item>
      <title>Script to do : Subtraction of multiple column</title>
      <link>https://community.jmp.com/t5/Discussions/Script-to-do-Subtraction-of-multiple-column/m-p/426029#M67564</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Need help to&amp;nbsp; develop one script to do subtraction of multiple column , column name and count is variable,&lt;/P&gt;&lt;P&gt;can change based on analysis,&lt;/P&gt;&lt;P&gt;Need to populate column delta with differences all the value from same row,&lt;/P&gt;&lt;P&gt;sample data as below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jinsejoseph_0-1634133124668.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/36532i41D16B6110A28B53/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jinsejoseph_0-1634133124668.png" alt="jinsejoseph_0-1634133124668.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;expected output:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jinsejoseph_0-1634137668769.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/36536i659BDAC7E5444808/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jinsejoseph_0-1634137668769.png" alt="jinsejoseph_0-1634137668769.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:38:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Script-to-do-Subtraction-of-multiple-column/m-p/426029#M67564</guid>
      <dc:creator>jinsejoseph</dc:creator>
      <dc:date>2023-06-10T23:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: Subtraction of multiple column</title>
      <link>https://community.jmp.com/t5/Discussions/Script-to-do-Subtraction-of-multiple-column/m-p/426034#M67565</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/32844"&gt;@jinsejoseph&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you give an example of the formula you want to use?&amp;nbsp; This sounds like something I would use the custom transformation in the&lt;LI-MESSAGE title="Scripting Tools" uid="410943" url="https://community.jmp.com/t5/JMP-Add-Ins/Scripting-Tools/m-p/410943#U410943" 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;add-in for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ih_0-1634133519854.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/36533i3D82AA8F775D1327/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ih_0-1634133519854.png" alt="ih_0-1634133519854.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Oct 2021 13:59:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Script-to-do-Subtraction-of-multiple-column/m-p/426034#M67565</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2021-10-13T13:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: Subtraction of multiple column</title>
      <link>https://community.jmp.com/t5/Discussions/Script-to-do-Subtraction-of-multiple-column/m-p/426039#M67566</link>
      <description>&lt;P&gt;Hi , Thanks for the reply,&lt;BR /&gt;I am using JMP15 can you help to point to the code that i can use,&lt;BR /&gt;I am a beginner in JMP&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Oct 2021 14:02:21 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Script-to-do-Subtraction-of-multiple-column/m-p/426039#M67566</guid>
      <dc:creator>jinsejoseph</dc:creator>
      <dc:date>2021-10-13T14:02:21Z</dc:date>
    </item>
    <item>
      <title>Re: Subtraction of multiple column</title>
      <link>https://community.jmp.com/t5/Discussions/Script-to-do-Subtraction-of-multiple-column/m-p/426080#M67569</link>
      <description>&lt;P&gt;Expected output in delta as below,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jinsejoseph_0-1634137515021.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/36535i5E5AC9529CC539DD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jinsejoseph_0-1634137515021.png" alt="jinsejoseph_0-1634137515021.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Oct 2021 15:05:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Script-to-do-Subtraction-of-multiple-column/m-p/426080#M67569</guid>
      <dc:creator>jinsejoseph</dc:creator>
      <dc:date>2021-10-13T15:05:23Z</dc:date>
    </item>
    <item>
      <title>Re: Subtraction of multiple column</title>
      <link>https://community.jmp.com/t5/Discussions/Script-to-do-Subtraction-of-multiple-column/m-p/426107#M67574</link>
      <description>&lt;P&gt;Now I see, in that case I would personally use the custom transformation function in the&lt;LI-MESSAGE title="Scripting Tools" uid="410943" url="https://community.jmp.com/t5/JMP-Add-Ins/Scripting-Tools/m-p/410943#U410943" 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;add-in.&amp;nbsp; I would select all of the columns you want to transform (I think data1-data10) and then select Custom Transformation from the Cols menu (available after installing the add-in) and enter these settings:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ih_0-1634139466162.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/36537i9BFAB11473958AAF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ih_0-1634139466162.png" alt="ih_0-1634139466162.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Oct 2021 15:38:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Script-to-do-Subtraction-of-multiple-column/m-p/426107#M67574</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2021-10-13T15:38:28Z</dc:date>
    </item>
    <item>
      <title>Re: Subtraction of multiple column</title>
      <link>https://community.jmp.com/t5/Discussions/Script-to-do-Subtraction-of-multiple-column/m-p/426115#M67576</link>
      <description>&lt;P&gt;Hi ,&lt;BR /&gt;I was writing a scrip for data analysis, and need this to be implement this logic in between the code only for one data table,&lt;BR /&gt;can you help to point to the code that i can use&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Oct 2021 15:55:14 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Script-to-do-Subtraction-of-multiple-column/m-p/426115#M67576</guid>
      <dc:creator>jinsejoseph</dc:creator>
      <dc:date>2021-10-13T15:55:14Z</dc:date>
    </item>
    <item>
      <title>Re: Subtraction of multiple column</title>
      <link>https://community.jmp.com/t5/Discussions/Script-to-do-Subtraction-of-multiple-column/m-p/426126#M67579</link>
      <description>&lt;P&gt;Here is the formula that I would use.&amp;nbsp; It relies on the matrix function Loc() which return all non zero entries in a matrix.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;x = :data[Row()] || :data1[Row()] || 
:data2[Row()] || :data3[Row()] || 
:data4[Row()] || :data5[Row()] ||
:data6[Row()] || :data7[Row()] || 
:data8[Row()] || :data9[Row()];
y = Loc( x );
Try( x[y[2]] - x[y[1]], . );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Oct 2021 16:05:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Script-to-do-Subtraction-of-multiple-column/m-p/426126#M67579</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-10-13T16:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: Subtraction of multiple column</title>
      <link>https://community.jmp.com/t5/Discussions/Script-to-do-Subtraction-of-multiple-column/m-p/426247#M67604</link>
      <description>&lt;P&gt;Hi Jim,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the input,&lt;/P&gt;&lt;P&gt;But column name is variable control and name can change based on run to run,&lt;/P&gt;&lt;P&gt;how to code in that situation ?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 02:37:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Script-to-do-Subtraction-of-multiple-column/m-p/426247#M67604</guid>
      <dc:creator>jinsejoseph</dc:creator>
      <dc:date>2021-10-14T02:37:15Z</dc:date>
    </item>
    <item>
      <title>Re: Subtraction of multiple column</title>
      <link>https://community.jmp.com/t5/Discussions/Script-to-do-Subtraction-of-multiple-column/m-p/426253#M67605</link>
      <description>&lt;P&gt;Assuming you don't know the names, and you don't know the number of columns, the below code will create the required formula, and then create the new column with the generated formula&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Current Data Table();

// Get the columns
colNames = dt &amp;lt;&amp;lt; get column names( string, continuous );

// Build the formula
theExpr = "dt&amp;lt;&amp;lt;new column(\!"Delta\!",formula(x = " || colNames[1] || "[Row()]";
For( i = 2, i &amp;lt;= N Items( colNames ), i++,
	theExpr = theExpr || " || " || colNames[i] || "[Row()]"
);
theExpr = theExpr || ";
y = Loc( x );
Try( x[y[2]] - x[y[1]], . )));";

// Execute the Created JSL
Eval( Parse( theExpr ) );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="txnelson_0-1634181607565.png" style="width: 703px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/36555i4F8156DD457408B0/image-dimensions/703x383?v=v2" width="703" height="383" role="button" title="txnelson_0-1634181607565.png" alt="txnelson_0-1634181607565.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The sample data table I used is attached&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 03:21:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Script-to-do-Subtraction-of-multiple-column/m-p/426253#M67605</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-10-14T03:21:35Z</dc:date>
    </item>
    <item>
      <title>Re: Subtraction of multiple column</title>
      <link>https://community.jmp.com/t5/Discussions/Script-to-do-Subtraction-of-multiple-column/m-p/426260#M67606</link>
      <description>&lt;P&gt;You could also turn it into a function if you need to use it multiple times.&lt;/P&gt;&lt;P&gt;Here is one example:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Function&lt;/LI&gt;&lt;LI&gt;Uses regex to filter down to the columns of interest&lt;/LI&gt;&lt;LI&gt;Requires JMP16 due to Filter Each&lt;/LI&gt;&lt;LI&gt;Uses Loc() and matrix calculations&lt;/LI&gt;&lt;LI&gt;Creates new column delta with the values&lt;/LI&gt;&lt;/UL&gt;&lt;PRE&gt;&lt;CODE class=""&gt;Names Default To Here(1);

//example datatable
dt = New Table("Untitled",
	Add Rows(5),
	Compress File When Saved(1),
	New Column("Column 1",
		Numeric,
		"Continuous",
		Format("Best", 12),
		Set Values([1, 0, 0, 1, 0]),
		Set Display Width(55)
	),
	New Column("Column 2", Numeric, "Continuous", Format("Best", 12), Set Values([0, 2, 3, 0, 0])),
	New Column("Column 3",
		Numeric,
		"Continuous",
		Format("Best", 12),
		Set Values([0, 3, 0, 0, 0]),
		Set Display Width(87)
	),
	New Column("Column 4", Numeric, "Continuous", Format("Best", 12), Set Values([3, 0, 4, 0, 0])),
	New Column("col", Character, "Nominal", Set Values({"a", "a", "a", "a", "a"}))
);


difference_between_min_max = Function({dt_ref, col_prefix_regex},
	{Default Local},
	//get columnn names of interest based on col_prefix
	col_names_all = dt_ref &amp;lt;&amp;lt; Get Column Names("Numeric", "String");
	col_names_of_interest = Filter Each({val}, col_names_all, 
		!IsMissing(Regex(val, col_prefix_regex));
	);
	show(col_names_of_interest);
	//all values for columns of interest, transpose for calculations
	m = Transpose(dt_ref[0, col_names_of_interest]);
	//replace 0 with missing to avoid calculation with those
	m[Loc(m, 0)] = .;
	//Get max and min values and deduct them
	result = V Max(m) - V Min(m);
	//Replace missing values with 0 for final results
	result[Loc(result,.)] = 0;
	//we could return result matrix here OR we can create new column with the function
	dt_ref &amp;lt;&amp;lt; New Column("delta", Numeric, Continuos, Set Values(result));
);

//example table in this example
difference_between_min_max(dt, "(Column )");

//example table by txnelson
//difference_between_min_max(Current Data Table(), "^(\D{1})$");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could also turn it into &lt;A href="https://www.jmp.com/support/help/en/16.1/#page/jmp/create-custom-functions-transforms-and-formats.shtml" target="_blank" rel="noopener"&gt;Custom Function&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 05:45:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Script-to-do-Subtraction-of-multiple-column/m-p/426260#M67606</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-10-14T05:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: Subtraction of multiple column</title>
      <link>https://community.jmp.com/t5/Discussions/Script-to-do-Subtraction-of-multiple-column/m-p/426265#M67609</link>
      <description>&lt;P&gt;Hi Jim,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the help,&lt;/P&gt;&lt;P&gt;solution working fine :)&lt;/img&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 08:02:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Script-to-do-Subtraction-of-multiple-column/m-p/426265#M67609</guid>
      <dc:creator>jinsejoseph</dc:creator>
      <dc:date>2021-10-14T08:02:31Z</dc:date>
    </item>
  </channel>
</rss>

