Here is a script that should give you a start at putting your final script together. It creates some sample tables to use for the example, and then finds them and matches on the first 2 characters in the name and finally concatenates them.
Names Default To Here( 1 );
// create sample data tables
For( i = 1, i <= 6, i++,
New Table( "M" || Char( Mod( i, 3 ) + 1 ) || Char( i ), New Column( "D" ) );
Data Table( "M" || Char( Mod( i, 3 ) + 1 ) || Char( i ) ) << add rows( 1 );
Column( Data Table( "M" || Char( Mod( i, 3 ) + 1 ) || Char( i ) ), 1 )[1] = i;
);
// Find all data tables that match Mx
concatTableList = {};
shortNameList = {};
For( i = 1, i <= N Table(), i++,
If( Starts With( Data Table( i ) << get name, "M" ),
Insert Into( concatTableList, Data Table( i ) << get name );
Insert Into( shortNameList, Substr( Data Table( i ) << get name, 1, 2 ) );
)
);
// Find the unique key values
theKeys = Associative Array( shortNameList ) << get keys;
// Create the concatenated tables
For Each( {key}, theKeys,
catList = {};
For Each( {tableName}, concatTableList,
If( Starts With( tableName, key ),
Insert Into( catList, tableName )
)
);
If( N Items( catList ) > 1,
dt = New Table( key );
For Each( {cat}, catList, dt << concatenate( Data Table( cat ), append to first table ) );
);
);
Jim