JMP 18: Select All Columns to the Right of a Specified ColumnLooking to select all columns to the right of the column named , Adders. The code below runs but does not visibly select the columns to the right of Adders. The number of columns to the left and right of Adders may vary.
<JSL> Names Default To Here(1);
dt = Data Table("Test Table");
dt << Bring Window To Front;
Show(dt << Get Name);
// Step 1: Get all column names and show them
colNames = dt << Get Column Names();
Show(colNames);
// Step 2: Find the index of the "Adders" column
targetColName = "Adders";
colIndex = Loc(colNames, targetColName);
Show(colIndex); // Should be > 0 if found
// Step 3: Try to visually select all columns to the right
If(colIndex > 0 & colIndex < N Cols(dt),
dt << Clear Column Selection;
For(i = colIndex + 1, i <= N Cols(dt), i++,
Column(dt, i) << Set Selected(1);
);
// Step 4: Show what JMP thinks is selected
selected = dt << Get Selected Columns;
Show(selected);
,
New Window("Error", Text Box("Column 'Adders' not found, or it's the last column."));
);</JSL>
Output:
dt << Get Name = "Test Table";
colNames = {A, B, Adders, X, Y};
colIndex = [];Automation and ScriptingWindowsRe: JMP 18: Select All Columns to the Right of a Specified ColumnI'd make two changes here. You need to specify "string" in your Get Column Names message. You should then change the Loc() function to Contains(). Loc() returns a matrix, sometimes empty. Contains() returns an integer (0 when not found).
Names Default To Here(1);
dt = Data Table("Test Table");
dt << Bring Window To Front;
Show(dt << Get Name);
// Step 1: Get all column names and show them
colNames = dt << Get Column Names( "string" );
Show(colNames);
// Step 2: Find the index of the "Adders" column
targetColName = "Adders";
colIndex = Contains(colNames, targetColName);
Show(colIndex); // Should be > 0 if found
// Step 3: Try to visually select all columns to the right
If(colIndex > 0 & colIndex < N Cols(dt),
dt << Clear Column Selection;
For(i = colIndex + 1, i <= N Cols(dt), i++,
Column(dt, i) << Set Selected(1);
);
// Step 4: Show what JMP thinks is selected
selected = dt << Get Selected Columns;
Show(selected);
,
New Window("Error", Text Box("Column 'Adders' not found, or it's the last column."));
);
//Output:
//dt << Get Name = "Test Table";
//colNames = {"A", "B", "Adders", "X", "Y"};
//colIndex = 3;<BR />//selected = {:X, :Y};Re: JMP 18: Select All Columns to the Right of a Specified ColumnI'm sure there are other ways to do this, but the following script will find the "Adders" column, then select it and all the columns to the right:
names default to here(1);
dt = current data table();
targetCol = "Adders";
targetColNum = 0;
for( i = 1, i <= n cols( dt ), i++,
if( column( dt,i ) << get name == targetCol, targetColNum = i )
);
dt << select columns( targetColNum::n cols(dt) )
Re: JMP 18: Select All Columns to the Right of a Specified ColumnI edited your initial post and moved the JSL and its output into a JSL window and a Code window respectively, by using the input icons at the top of the edit input window.
I have also modified your code to have the << get column names, return strings, and instead of using Loc(), using Contains() to return a single value rather than a matrix value.
Names Default To Here(1);
dt = Data Table("Test Table");
dt << Bring Window To Front;
Show(dt << Get Name);
// Step 1: Get all column names and show them
colNames = dt << Get Column Names(string);
Show(colNames);
// Step 2: Find the index of the "Adders" column
targetColName = "Adders";
// Loc() returns a matrix, contains returns a scaler value
colIndex = contains(colNames, targetColName );
Show( colIndex ); // Should be > 0 if found
// Step 3: Try to visually select all columns to the right
If( colIndex > 0 & colIndex < N Cols( dt ),
dt << Clear Column Selection;
For( i = colIndex + 1, i <= N Cols( dt ), i++,
Column( dt, i ) << Set Selected( 1 )
);
// Step 4: Show what JMP thinks is selected
selected = dt << Get Selected Columns;
Show( selected );
,
New Window( "Error", Text Box( "Column 'Adders' not found, or it's the last column." ) )
);Re: JMP 18: Select All Columns to the Right of a Specified ColumnThank you for the corrections.
Re: JMP 18: Select All Columns to the Right of a Specified ColumnJim: Thank you for the corrections.
Re: JMP 18: Select All Columns to the Right of a Specified ColumnScott: Thank you for the code which works.
Re: JMP 18: Select All Columns to the Right of a Specified ColumnContains + indexing using that should make this fairly simple
Names Default To Here(1);
dt = Data Table("Test Table");
collist = dt << Get Column Names("String");
adders_idx = Contains(collist, "Adders");
If(adders_idx == 0,
Throw("No Adders column found");
);
dt << Select columns(collist[adders_idx + 1::N Items(collist)]);
Show(dt << Get Selected Columns);