Here is a Join centric version of a script that will work....it should be pretty efficient
names default to here(1);
dtA = data table("A");
dtB = data table("B");
// Create data tables with only the data required
dtAID = dtA << Subset(invisible, selected rows(0), columns(:ID));
dtBID = dtB << Subset(invisible, selected rows(0), columns(:ID));
// Create a data table with only IDs found in both tables
dtABID = dtAID << Join(invisible, with(dtBID ),
Merge Same Name Columns,
By Matching Columns( :ID = :ID ),
Drop multiples( 0, 0 ),
Include Nonmatches( 0, 0 ),
Preserve main table order( 1 )
);
close( dtAID, nosave );
close( dtBID, nosave );
// Create a table with only 1 row for each ID found
dtSum = dtABID << Summary(invisible,
Group( :ID ),
Freq( "None" ),
Weight( "None" )
);
// Create a data table that only has the correct IDs
// from data table A
dtAMatches = dtA << Join(invisible,
with(dtSum ),
Merge Same Name Columns,
By Matching Columns( :ID = :ID ),
Drop multiples( 0, 0 ),
Include Nonmatches( 0, 0 ),
Preserve main table order( 1 )
);
close( dtSum, nosave );
// Delete column Match Flag and N Rows
dtAMatches << delete columns("Match Flag", "N Rows");
// Concatenate table B with the matched data from table A
dtFinal = dtB << Concatenate( dtAMatches );
close( dtAMatches, nosave );
Jim