If no duplication is allowed you could try using associative arrays and their set operations:
Names Default To Here(1);
dt = New Table("demo",
Add Rows(4),
New Column("A", Character, "Nominal", Set Values({"KDBAC", "FLGHEK", "ONLCQR", "WVTZXR"})),
New Column("B", Character, "Nominal", Set Values({"ROMNLQ", "DFBACE", "LKGHJK", "WVTZYX"}))
);
// Create lookup associative array, with row number as key and value as associative array with
// keys as characters in row. This will be used in union operations
aa_lookup = Associative Array();
For Each({val, idx}, dt:B << get values,
aa_lookup[idx] = Associative Array(Eval List(Words(val, "")));
);
// Create collection column
dt << New Column("C", Numeric, Continuous);
For Each Row(dt,
best_match = 0;
max_row = .;
For Each({{key, val}}, aa_lookup,
cur_aa = Associative Array(Eval List(Words(:A, "")));
cur_aa << Intersect(val);
cur_match = N Items(cur_aa);
If(cur_match > best_match,
best_match = cur_match;
max_row = key;
);
);
:C = max_row;
);
-Jarmo