I'm writing a helper function that renames the a column group if it contains a particular column name.
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Cities.jmp" );
/*//Use if already existing
dt = Data Table ("Cities");
*/
dt << group columns( "xy", {:X, :y} );
dt << group columns( "pollutants", :Ozone :: :Lead );
match_col = "X";
new_name = "coordinates";
groups_list = dt << get column groups names;
show(groups_list);
For Each({grp, ig}, groups_list,
cols = dt << get column group( grp );
show(cols);
For Each ({column, ic}, cols,
show(column);
colname = column << Get Name;
If(colname == match_col,
try(dt << rename column group( grp, new_name );)
)
);
);
This works fine with basic grouped columns, but falls over if there's an inherited group from a Link Reference:
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Cities.jmp" );
dt_state = Open( "$SAMPLE_DATA/State Abbreviations.jmp" );
//Need more than 1 column
dt_state << New Column( "Dummy", Numeric, "Continuous", Format( "Best", 12 ));
//Link Tables
dt_state:Abbreviations << Set Property( "Link ID", 1 );
dt:State << Set Property("Link Reference", Reference Table(dt_state));
/*//Use if already existing
dt = Data Table ("Cities");
dt_state = Data Table( "State Abbreviations" );
*/
dt << group columns( "xy", {:X, :y} );
dt << group columns( "pollutants", :Ozone :: :Lead );
match_col = "X";
new_name = "coordinates";
groups_list = dt << get column groups names;
show(groups_list);
For Each({grp, ig}, groups_list,
cols = dt << get column group( grp );
show(cols);
For Each ({column, ic}, cols,
show(column);
colname = column << Get Name;
If(colname == match_col,
try(dt << rename column group( grp, new_name );)
)
);
);
Firstly, the << Get Name function errors on :Ozone, which worked fine in the simpler example.
Even if that error is resolved, the linked column looks different in the Log:
column = :Y;
column = Referenced Column("U.S. States[State]", Reference(Column(:State), Reference(Column(:U.S. States))));
How do extract the text name? i.e "U.S. States[State]"