This solution looks complicated but the idea is: get list of all class columns and then use data table subscripting WITH that list and get maximum index of found values (so this assumes that the columns are ordered)
Names Default To Here(1);
dt = New Table("Untitled",
Add Rows(4),
Compress File When Saved(1),
New Column("n", Numeric, "Continuous", Format("Best", 12), Set Values([., ., ., .])),
New Column("Class A1", Character, "Nominal", Set Values({"A1", "", "A1", ""})),
New Column("Class A2", Character, "Nominal", Set Values({"", "A2", "A2", ""})),
New Column("Class A", Character, "Nominal", Set Values({"", "", "", "A"})),
New Column("Class B", Character, "Nominal", Set Values({"", "", "", "", "B"}))
);
col_list = dt << Get Column Names("String");
class_cols = {};
For(i = 1, i <= N Items(col_list), i++,
col_name = col_list[i];
If(Starts With(col_name, "Class "),
Insert Into(class_cols, col_name);
);
);
dt << New Column("CLASS GROUP", Character, Nominal, << Set Each Value(
valcol = Max(Loc(Matrix(!IsMissing(dt[Row(), class_cols])))) + 1;
dt[Row(), valcol];
));
-Jarmo