<?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: How to apply a script on subsets of a datatable in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-apply-a-script-on-subsets-of-a-datatable/m-p/615329#M81508</link>
    <description>&lt;P&gt;Just based on the script you have here, I would add index column, create subsets based on the unique letters, run formula on each of those and then update data back to original table&lt;/P&gt;</description>
    <pubDate>Wed, 22 Mar 2023 09:33:23 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2023-03-22T09:33:23Z</dc:date>
    <item>
      <title>How to apply a script on subsets of a datatable</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-apply-a-script-on-subsets-of-a-datatable/m-p/615309#M81506</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In my datatable I have 6 data subsets (distinguished one another by Column X where each subset has a different letter "a", "b", "c", "d", "e" and "f"). How could I apply a script to all 6 subsets independently and get the 6 results of my script in one column? &amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you in advance for your support!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Best&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Claire &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;------&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Script currently applied to entire datatable:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current Data Table();

dt &amp;lt;&amp;lt; New Column("sumtempj",
	Numeric,
	Continuous,
	&amp;lt;&amp;lt;Set Each Value(
		As Constant(
			ts = :"Rounded TempJ" &amp;lt;&amp;lt; get values;
			f_row = Min(Loc(ts, 121));
			t_idx = Index(f_row, f_row + 359);
			sumtempj = Sum(ts[t_idx]) - (360 * 121);
		);
		If(
			Row() == f_row, sumtempj,
			, .
		);
	)
);

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:59:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-apply-a-script-on-subsets-of-a-datatable/m-p/615309#M81506</guid>
      <dc:creator>cbaril</dc:creator>
      <dc:date>2023-06-10T23:59:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to apply a script on subsets of a datatable</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-apply-a-script-on-subsets-of-a-datatable/m-p/615329#M81508</link>
      <description>&lt;P&gt;Just based on the script you have here, I would add index column, create subsets based on the unique letters, run formula on each of those and then update data back to original table&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2023 09:33:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-apply-a-script-on-subsets-of-a-datatable/m-p/615329#M81508</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-03-22T09:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to apply a script on subsets of a datatable</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-apply-a-script-on-subsets-of-a-datatable/m-p/615434#M81520</link>
      <description>&lt;P&gt;Hi Jarmo,&lt;/P&gt;
&lt;P&gt;Thanks for the tip!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm only a beginner in JSL and now have this script (see below). The result column "sumtempj" appears in each sub datatable produced but there is no result in the column. Can you see the mistake?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best&lt;/P&gt;
&lt;P&gt;Claire&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Script:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current Data Table();

// Perform the subsets
listDT = dt &amp;lt;&amp;lt; Subset(
	By( :BBI and SteriRun ),
	All rows,
	Selected columns only( 0 ),
	columns( :RoundedTempJ, :BBI and SteriRun, :Sterilisation duration )
);

// Loop across all new data tables and run sumtempj
For( i = 1, i &amp;lt;= N Items( listDT ), i++,
	listDT[i] &amp;lt;&amp;lt; New Column( "sumtempj",
		Numeric,
		Continuous,
		&amp;lt;&amp;lt;Set Each Value(

			As Constant(
				ts = :Rounded TempJ &amp;lt;&amp;lt; get values;
				f_row = Min( Loc( ts, 121 ) );
				t_idx = Index( f_row, f_row + 359 );
				sumtempj = Sum( ts[t_idx] ) - (360 * 121);
			);
			If(
				Row() == f_row, sumtempj,
				, .
			);
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Mar 2023 13:21:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-apply-a-script-on-subsets-of-a-datatable/m-p/615434#M81520</guid>
      <dc:creator>cbaril</dc:creator>
      <dc:date>2023-03-22T13:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to apply a script on subsets of a datatable</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-apply-a-script-on-subsets-of-a-datatable/m-p/615448#M81525</link>
      <description>&lt;P&gt;There might be other ways of doing this, but as I don't know your data I cannot really suggest anything. Here is one solution which uses subsets which could work&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

// add indexing to original data
dt &amp;lt;&amp;lt; New Column("IDX", Numeric, Continuous, &amp;lt;&amp;lt; Set Each Value(Row()));
// add data column to table as empty
new_col = dt &amp;lt;&amp;lt; New Column("sumtempj", Numeric, Continuous);
col_name = new_col &amp;lt;&amp;lt; get name;
// get unique groups to uniq_vals
Summarize(dt, uniq_vals_str = by(:age));

// in this case we have to convert uniq_vals back to numeric values BUT it isn't always necessary
// (summarize changes them to strings)
uniq_vals = Transform Each({uniq_val_str}, uniq_vals_str, num(uniq_val_str));

// loop over those unique values 
For Each({uniq_val}, uniq_vals,
	// create subset
	uniq_val_rows = dt &amp;lt;&amp;lt; Get Rows Where(:age == uniq_val);
	dt_temp = dt &amp;lt;&amp;lt; Subset(rows(uniq_val_rows), output table(char(uniq_val)), invisible);
	
	// perform calculation
	Column(dt_temp, col_name) &amp;lt;&amp;lt; Set Each Value(
		Col Max(:height);
	);
	// update values
	dt &amp;lt;&amp;lt; Update(
		With(dt_temp),
		Match Columns(:IDX = :IDX)
	);
	// wait is here for demo purposes
	wait(1);
	close(dt_temp, no save);
);

dt &amp;lt;&amp;lt; Delete Columns("idx"); &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Mar 2023 14:07:58 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-apply-a-script-on-subsets-of-a-datatable/m-p/615448#M81525</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-03-22T14:07:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to apply a script on subsets of a datatable</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-apply-a-script-on-subsets-of-a-datatable/m-p/615489#M81528</link>
      <description>&lt;P&gt;This is a bit too advanced for me, but thank you for the inputs! I managed to find a way to get the result without too much manual handling and for now it's good enough.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Claire&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2023 14:58:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-apply-a-script-on-subsets-of-a-datatable/m-p/615489#M81528</guid>
      <dc:creator>cbaril</dc:creator>
      <dc:date>2023-03-22T14:58:50Z</dc:date>
    </item>
  </channel>
</rss>

