<?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: Create datatable by counting batches in table in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Create-datatable-by-counting-batches-in-table/m-p/863845#M102776</link>
    <description>&lt;P&gt;Thanks Jarmo! This is perfect.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;While writing this post, I was bragging about how incredible the JMP community is, and I was not disappointed!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers, Christian&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 01 Apr 2025 07:40:13 GMT</pubDate>
    <dc:creator>Stats_Like_Jazz</dc:creator>
    <dc:date>2025-04-01T07:40:13Z</dc:date>
    <item>
      <title>Create datatable by counting batches in table</title>
      <link>https://community.jmp.com/t5/Discussions/Create-datatable-by-counting-batches-in-table/m-p/863445#M102743</link>
      <description>&lt;P&gt;Hi JMP Community&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset that is only partially filled out with batch numbers.&lt;/P&gt;
&lt;P&gt;My goal is to make a dataset containing one row pr. batch.&lt;/P&gt;
&lt;P&gt;I can calculate how many rows are needed by comparing the first and last batch numbers.&lt;/P&gt;
&lt;P&gt;As seen in the example I would need a dataset with 30 rows as the first batch no. is 7 and the last is 37.&lt;/P&gt;
&lt;P&gt;In the batch name, the 3 first and 2 last digits should be ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my mind, this should be straight forward, but I am stuck…&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would highly appreciate getting unstuck!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Christian&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Mar 2025 13:34:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-datatable-by-counting-batches-in-table/m-p/863445#M102743</guid>
      <dc:creator>Stats_Like_Jazz</dc:creator>
      <dc:date>2025-03-31T13:34:50Z</dc:date>
    </item>
    <item>
      <title>Re: Create datatable by counting batches in table</title>
      <link>https://community.jmp.com/t5/Discussions/Create-datatable-by-counting-batches-in-table/m-p/863467#M102745</link>
      <description>&lt;P&gt;Hmmm I don't understand your query? &amp;nbsp;You have multiple rows with identical information (first 3, and rows 4 &amp;amp; 5), you are missing the rows with 21-23, 25-26, 29? &amp;nbsp;Also the first 6 digits are identical.&lt;/P&gt;
&lt;P&gt;What exactly do you want to do? &amp;nbsp;You can always right click on the column and use recode.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Mar 2025 13:59:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-datatable-by-counting-batches-in-table/m-p/863467#M102745</guid>
      <dc:creator>statman</dc:creator>
      <dc:date>2025-03-31T13:59:45Z</dc:date>
    </item>
    <item>
      <title>Re: Create datatable by counting batches in table</title>
      <link>https://community.jmp.com/t5/Discussions/Create-datatable-by-counting-batches-in-table/m-p/863468#M102746</link>
      <description>&lt;P&gt;Something like this?&amp;nbsp; It creates a new table with a single row for each batch, instead of multiple rows and fills in the missing batches.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
Batch_vals = Associative Array( :Batch ) &amp;lt;&amp;lt; Get Keys;
prefix = Left( :Batch[1], 3 );
suffix = Right( :Batch[1], 2 );
rootlength = Length( Batch_vals[1] ) - Length( prefix ) - Length( suffix );
Batch_nums = Transform Each( {v, i}, Batch_vals, Num( Substitute( v, {prefix, suffix}, "" ) ) );
Min_batch = Min( Batch_nums );
Max_batch = Max( Batch_nums );
Batches = Min_batch :: Max_batch;
dt = New Table( "Batches", New Column( "Batch Number", numeric, continuous, Set Values( Batches ) ) );
Eval(
	Eval Expr(
		dt &amp;lt;&amp;lt; New Column( "Batch", character, Formula( Expr( prefix ) || Right( Char( :Batch Number ), rootlength, "0" ) || Expr( suffix ) ) )
	)
);
dt:Batch &amp;lt;&amp;lt; Delete Formula;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Mar 2025 14:05:10 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-datatable-by-counting-batches-in-table/m-p/863468#M102746</guid>
      <dc:creator>mmarchandFSLR</dc:creator>
      <dc:date>2025-03-31T14:05:10Z</dc:date>
    </item>
    <item>
      <title>Re: Create datatable by counting batches in table</title>
      <link>https://community.jmp.com/t5/Discussions/Create-datatable-by-counting-batches-in-table/m-p/863789#M102770</link>
      <description>&lt;P&gt;This won't create batch numbers but just the numbers.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Data Table("Format");

Summarize(dt, uniq = By(:Batch));

first_val = Num(Substr(uniq[1], 4, Length(uniq[1]) - 5));
last_val = Num(Substr(uniq[N Items(uniq)], 4, Length(uniq[1]) - 5));

dt = New Table("Res",
	New Column("R", Numeric, Ordinal, Values(first_val::last_val))
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can add batch numbers back by transforming that item list to string and create table from that (same first_val and last_val as in previous)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;batches = Transform Each({item}, As List((first_val::last_val)`),
	"245" || Right("00000" || Char(item), 5) || "00"
);
dt = New Table("Res2",
	New Column("R", Character, Ordinal, Values(batches))
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Apr 2025 05:02:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-datatable-by-counting-batches-in-table/m-p/863789#M102770</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-04-01T05:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: Create datatable by counting batches in table</title>
      <link>https://community.jmp.com/t5/Discussions/Create-datatable-by-counting-batches-in-table/m-p/863845#M102776</link>
      <description>&lt;P&gt;Thanks Jarmo! This is perfect.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;While writing this post, I was bragging about how incredible the JMP community is, and I was not disappointed!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers, Christian&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Apr 2025 07:40:13 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-datatable-by-counting-batches-in-table/m-p/863845#M102776</guid>
      <dc:creator>Stats_Like_Jazz</dc:creator>
      <dc:date>2025-04-01T07:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: Create datatable by counting batches in table</title>
      <link>https://community.jmp.com/t5/Discussions/Create-datatable-by-counting-batches-in-table/m-p/863847#M102777</link>
      <description>&lt;P&gt;Thanks for the reply&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/58003"&gt;@mmarchandFSLR&lt;/a&gt;!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your script works perfectly!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your solution contains some prompts/scripts that are new to me, e.g., Associative Array, Transform Each, Eval, Eval Expr.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking forward to digging into how your solution works!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While writing this post, I bragged about how incredible the JMP community is and was not disappointed!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cheers, Christian&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Apr 2025 07:44:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-datatable-by-counting-batches-in-table/m-p/863847#M102777</guid>
      <dc:creator>Stats_Like_Jazz</dc:creator>
      <dc:date>2025-04-01T07:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: Create datatable by counting batches in table</title>
      <link>https://community.jmp.com/t5/Discussions/Create-datatable-by-counting-batches-in-table/m-p/863932#M102782</link>
      <description>&lt;P&gt;Simple explanation of some of those functions and an important alteration:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
//An associative array is a dictionary or hash map that links keys to values.  Each key must be unique.
//Using a single column as the argument for the array gives us the unique values of the column with each value set to 1
//The &amp;lt;&amp;lt;Get Keys message then yields the keys only, so Associative Array( :Column ) &amp;lt;&amp;lt; Get Keys is a way to get unique column values
//Jarmo's example of Summarize() does the same thing and is probably a better method, but the array method works on lists, too
Batch_vals = Associative Array( :Batch ) &amp;lt;&amp;lt; Get Keys;
prefix = Left( :Batch[1], 3 );
suffix = Right( :Batch[1], 2 );
rootlength = Length( Batch_vals[1] ) - Length( prefix ) - Length( suffix );
//Transform Each performs the same action on each item in a list, matrix, or associative array and returns the transformed values in the same container
//I should have done this differently to avoid unintended substitutions, since a batch value that matched the prefix or suffix would be deleted.
//Batch_nums = Transform Each( {v, i}, Batch_vals, Num( Substitute( v, {prefix, suffix}, "" ) ) );
Batch_nums = Transform Each( {v, i}, Batch_vals, Num( Substr( v, Length( prefix ) + 1, rootlength ) ) );
Min_batch = Min( Batch_nums );
Max_batch = Max( Batch_nums );
Batches = Min_batch :: Max_batch;
dt = New Table( "Batches", New Column( "Batch Number", numeric, continuous, Set Values( Batches ) ) );
//Eval() always evaluates the code inside
//Eval Expr() evaluates all expressions inside before running the code
//When setting a column formula based on the value of a variable, I wrap that variable inside of Expr() and then use Eval( Eval Expr() )
//to pass the VALUE of the variable into the column formula, rather than passing the variable itself
//In this case, it wouldn't matter, since I delete the formula immediately after creation, but it's good practice
Eval(
	Eval Expr(
		dt &amp;lt;&amp;lt; New Column( "Batch", character, Formula( Expr( prefix ) || Right( Char( :Batch Number ), rootlength, "0" ) || Expr( suffix ) ) )
	)
);
dt:Batch &amp;lt;&amp;lt; Delete Formula;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Apr 2025 11:46:10 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-datatable-by-counting-batches-in-table/m-p/863932#M102782</guid>
      <dc:creator>mmarchandFSLR</dc:creator>
      <dc:date>2025-04-01T11:46:10Z</dc:date>
    </item>
    <item>
      <title>Re: Create datatable by counting batches in table</title>
      <link>https://community.jmp.com/t5/Discussions/Create-datatable-by-counting-batches-in-table/m-p/865695#M102876</link>
      <description>&lt;P&gt;You can create rows by incrementing the batch numbers sequentially.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Apr 2025 07:37:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-datatable-by-counting-batches-in-table/m-p/865695#M102876</guid>
      <dc:creator>AshleyWhitaker</dc:creator>
      <dc:date>2025-04-04T07:37:40Z</dc:date>
    </item>
  </channel>
</rss>

