Subscribe Bookmark RSS Feed

JSL keep command to keep wanted variables and delete unwanted variables?


Community Trekker


Mar 12, 2015

I am looking for a JSL script command to "keep" only specified column variables, and delete all other variables in the current data table.

This would be the inverse of the specified command:  dt << Delete Columns( :A, :B, ... :N);

Ideally a more efficient keep command would appear like:

dt = Current Data Table( );

dt << Keep Columns ( :time, :day, :location );

(outcome = Delete all columns that do not equal :time, :day, :location).



Super User


Jun 22, 2012

I assume that you are making a feature enhancement request.  You will be better served if you submit this to


Super User


Jun 23, 2011

Until they add it to JSL you can try this:

Re: Deleting columns that are not in a list

it could be further developed and i found it very useful before using the table update command.

Before updating tables it is useful to remove columns that have same name but you do not wish to update. The following will do it just by defining the to keep columns.


dt10 = New Table( "Test",

     Add Rows( 10 ),

     New Column( "A" ),

     New Column( "B" ),

     New Column( "C" ),

     New Column( "D" )


Keep = {"A", "C"};

todelete = dt10 << get column names( "string" );

For( in = 1, in <= N Items( Keep ), in++, // assuming the to keep list is shorter than the list of columns in the table.

location = Contains( todelete, Keep[in]) ; // find the location of the keepers

if (location > 0, Remove From( todelete, location, 1 ) // if found remove it


if (nitems (todelete) > 0, dt10 << delete columns( todelete )); // if there is a delete list delete the columns from the table

if you ask the development team for this command ask them to make the same for rows.




Community Trekker


Mar 12, 2015

Thank you.  Your script above was helpful.

I modified slightly to operate in current data table, eg Data Table( "name_here") compared to creating a new data table and the outcome was successful. 


Super User


Jul 28, 2015

Probably a simpler solution that is easy to do manually (and script easily) is to just subset your data.

Select the Columns you want to keep and then subset with the Selected Columns(1) option.  This should also be faster than the method described above when the data table gets large, but I haven't tested it.