<?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 Faster iteration in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Faster-iteration/m-p/769193#M94966</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Trying to optimize the iterations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a reference table where each column is a name from a main data table column. I want to iterate through each row of the reference data table and then add the values from &lt;STRONG&gt;Column(dt_main, "Values") to New A and New B Columns in the reference table if Column(dt_ref, "Nrows")&amp;gt;2 &amp;amp; Comment[i] == "A &amp;gt; B".&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using an associative array because I am interested only in the last recorded values of each type A and B, mapped to the corresponding X/Y/Wafer ID.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The below script takes a very long time. Is there a way to optimize?&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 );
start = Tick Seconds();
dt_main = Data Table( "maintable" );
dt_ref = Data Table( "referencetable" );


Try( dt_ref &amp;lt;&amp;lt; delete columns( :New N, :New R ) );
dt_ref &amp;lt;&amp;lt; New Column( "New A", "Numeric" );
dt_ref &amp;lt;&amp;lt; New Column( "New B", "Numeric" );
nrows = [];

For( nn = 1, nn &amp;lt;= N Rows( dt_ref ), nn++, 
	
	Insert Into( nrows, nn )
);

dt_ref &amp;lt;&amp;lt; begin data update;
For Each( {r, i}, nrows, 
	
	
	If( dt_ref:N Rows[i] &amp;gt; 2 &amp;amp; dt_ref:Comment[i] == "A &amp;gt; B", 
/// Create AA to get the last recorded values for each A and B to the corresponding X/Y/Wafer ID from dt_main
		countsessions = Associative Array(
			dt_main:Type[dt_main &amp;lt;&amp;lt; get rows where( dt_main:X Coord == dt_ref:X Coord[i] &amp;amp; dt_main:Y Coord == dt_ref:Y Coord[i] &amp;amp; dt_main:Wafer ID == dt_ref:Wafer ID[i] )], 
			
			dt_main:Value[dt_main &amp;lt;&amp;lt; get rows where( dt_main:X Coord == dt_ref:X Coord[i] &amp;amp; dt_main:Y Coord == dt_ref:Y Coord[i] &amp;amp; dt_main:Wafer ID == dt_ref:Wafer ID[i] )];
			
		);
		
		Try( dt_ref:New A[i] = countsessions["A"] );
		Try( dt_ref:New B[i] = countsessions["B"] );
		
	)
);

dt_ref &amp;lt;&amp;lt; end data update;
end = Tick Seconds();

Show( Char( end - start ) );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Jun 2024 13:00:54 GMT</pubDate>
    <dc:creator>Jackie_</dc:creator>
    <dc:date>2024-06-28T13:00:54Z</dc:date>
    <item>
      <title>Faster iteration</title>
      <link>https://community.jmp.com/t5/Discussions/Faster-iteration/m-p/769193#M94966</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Trying to optimize the iterations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a reference table where each column is a name from a main data table column. I want to iterate through each row of the reference data table and then add the values from &lt;STRONG&gt;Column(dt_main, "Values") to New A and New B Columns in the reference table if Column(dt_ref, "Nrows")&amp;gt;2 &amp;amp; Comment[i] == "A &amp;gt; B".&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using an associative array because I am interested only in the last recorded values of each type A and B, mapped to the corresponding X/Y/Wafer ID.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The below script takes a very long time. Is there a way to optimize?&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 );
start = Tick Seconds();
dt_main = Data Table( "maintable" );
dt_ref = Data Table( "referencetable" );


Try( dt_ref &amp;lt;&amp;lt; delete columns( :New N, :New R ) );
dt_ref &amp;lt;&amp;lt; New Column( "New A", "Numeric" );
dt_ref &amp;lt;&amp;lt; New Column( "New B", "Numeric" );
nrows = [];

For( nn = 1, nn &amp;lt;= N Rows( dt_ref ), nn++, 
	
	Insert Into( nrows, nn )
);

dt_ref &amp;lt;&amp;lt; begin data update;
For Each( {r, i}, nrows, 
	
	
	If( dt_ref:N Rows[i] &amp;gt; 2 &amp;amp; dt_ref:Comment[i] == "A &amp;gt; B", 
/// Create AA to get the last recorded values for each A and B to the corresponding X/Y/Wafer ID from dt_main
		countsessions = Associative Array(
			dt_main:Type[dt_main &amp;lt;&amp;lt; get rows where( dt_main:X Coord == dt_ref:X Coord[i] &amp;amp; dt_main:Y Coord == dt_ref:Y Coord[i] &amp;amp; dt_main:Wafer ID == dt_ref:Wafer ID[i] )], 
			
			dt_main:Value[dt_main &amp;lt;&amp;lt; get rows where( dt_main:X Coord == dt_ref:X Coord[i] &amp;amp; dt_main:Y Coord == dt_ref:Y Coord[i] &amp;amp; dt_main:Wafer ID == dt_ref:Wafer ID[i] )];
			
		);
		
		Try( dt_ref:New A[i] = countsessions["A"] );
		Try( dt_ref:New B[i] = countsessions["B"] );
		
	)
);

dt_ref &amp;lt;&amp;lt; end data update;
end = Tick Seconds();

Show( Char( end - start ) );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2024 13:00:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Faster-iteration/m-p/769193#M94966</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2024-06-28T13:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: Faster iteration</title>
      <link>https://community.jmp.com/t5/Discussions/Faster-iteration/m-p/769344#M94996</link>
      <description>&lt;P&gt;I took a different route, using the built in JMP Select, Join, Split and Update platforms.&amp;nbsp; It works very fast, and I appear to get the same results, except for the A&amp;gt;B rows that in your reference table have missing values....but the values I come up with match the N(A) and N(b) columns.&amp;nbsp; So I may be completely off base.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
start = Tick Seconds();
dt_main = Data Table( "maintable" );
dt_ref = Data Table( "referencetable" );


Try( dt_ref &amp;lt;&amp;lt; delete columns( :New A, :New B ) );

// Create a subset of the maintable that contains only data for the rows in
// the reference table that have comment value of A&amp;gt;B
// Select only A&amp;gt;B rows in reference table
dt_ref &amp;lt;&amp;lt; select where(:Comment == "A &amp;gt; B");
dtAB = dt_ref&amp;lt;&amp;lt;subset( selected rows(1), columns(:X Coord,:Y Coord,:Wafer ID));

// Use Join to create a new main table with only matching wafer, x, y
dtMainJoin = dt_main &amp;lt;&amp;lt; Join(
	With( dtAB ),
	Merge Same Name Columns,
	Match Flag( 0 ),
	By Matching Columns(
		:X Coord = :X Coord, :Y Coord = :Y Coord, :Wafer ID = :Wafer ID
	),
	Drop multiples( 0, 0 ),
	Include Nonmatches( 0, 0 ),
	Preserve main table order( 1 ),
	Output Table( "Join of maintable with Subset of referencetable 2" )
);

// Clean up by deleting dtAB
close( dtAB, nosave );

// Get rid of duplicate data, saving only the last values.
// Use Select Duplicate Rows() to find the duplicates, but since it retains the 1st
// row found, reverse the data table and then apply Select Duplicate Rows()
dtMainJoin &amp;lt;&amp;lt; New Column("RowNum", set each value(Row()));

dtMainJoin = dtMainJoin &amp;lt;&amp;lt; sort(by(:RowNum), Order(descending), Replace table(1));
found = dtMainJoin &amp;lt;&amp;lt; Select Duplicate Rows(match(:Type, :X Coord, :Y Coord, :Wafer ID));

If(found&amp;gt;0, dtMainJoin &amp;lt;&amp;lt; delete rows);
dtMainJoin = dtMainJoin &amp;lt;&amp;lt; sort(by(:RowNum), Order(ascending), Replace table(1));
dtMainJoin &amp;lt;&amp;lt; delete columns(:RowNum);

// Split the table to create the New A and New B Columns
dtSplit = dtMainJoin &amp;lt;&amp;lt;
Split(
	Split By( :Type ),
	Split( :Value ),
	Group( :X Coord, :Y Coord, :Wafer ID ),
	Output Table(
		"Split of Join of maintable with Subset of referencetable 2 by Type"
	),
	Sort by Column Property
);

// Clean up dtMainJoin table by closing it
close(dtMainJoin, nosave);

// Rename the A and B columns
dtSplit:A &amp;lt;&amp;lt; set name("New A");
dtSplit:B &amp;lt;&amp;lt; set name("New B");

// Use Update to merge the dtSplit data into the reference table
dt_ref &amp;lt;&amp;lt; Update(
	With(
		Data Table(
			dtSplit
		)
	),
	Match Columns( :X Coord = :X Coord, :Y Coord = :Y Coord, :Wafer ID = :Wafer ID )
);

// Clean up
close( dtSplit, nosave );

dt_ref &amp;lt;&amp;lt; end data update;
end = Tick Seconds();

Show( Char( end - start ) );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 29 Jun 2024 03:17:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Faster-iteration/m-p/769344#M94996</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2024-06-29T03:17:24Z</dc:date>
    </item>
  </channel>
</rss>

