Scripting Guide > Data Tables > Columns > Use Set Selected to Select Columns
Publication date: 08/13/2020

Use Set Selected to Select Columns

Send the Set Selected message to select a column.

col << Set Selected( 1 );

To select all columns with a specific string in the name, run the following script:

dt = Open( "$SAMPLE_DATA/Semiconductor Capability.jmp" );
 
colList = dt << Get Column Names( String );
 
For( i = 1, i <= N Cols( dt ), i++,
	If( Contains( colList[i], "NPN" ), /* select only columns with NPN
														in the name */
		Column( colList[i] ) << Set Selected( 1 )
	)
);

If you want to select many columns, consider sending the Select Columns message to the data table. See Close a Data Table.

Get Selected Columns

To get a list of currently selected columns, use the Get Selected Columns message.

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
:age << Set Selected( 1 );
:sex << Set Selected( 1 );
dt << Get Selected Columns();

{:age, :sex}

Return the list of selected columns as a string using the string argument:

dt << Get Selected Columns( string );

{"age", "sex", "height"}

Once you know what columns are selected, you can then write a script that acts upon these columns. Or your script can iteratively select columns and act upon them one at a time.

To actually select the columns before getting the columns, send the Set Selected message to a column. See Column Attributes.

Go To Column

To select and move to a specific column, use the Go To message.

dt << Go To( column name | column number );

For data tables with many columns, you can use this message to scroll the data table all the way to the left, so that the first column comes into view and is selected:

dt = Open( "$SAMPLE_DATA/Tiretread.jmp" );
dt << Go To( 1 );

Invert Column Selections

To select any column that is currently deselected and deselect any column that is currently selected, use the Invert Column Selection message.

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt:age << Set Selected( 1 );
dt:height << Set Selected( 1 );
Wait( 1 );
b = dt << Invert Column Selection;

If a list of columns is provided, the columns that are not in the list are selected.

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
a = {:height, :weight};
b = dt << Invert Column Selection( a );
Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).
.