cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
aandw
Level II

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

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).

Thanks.

3 ACCEPTED SOLUTIONS

Accepted Solutions
ron_horne
Super User (Alumni)

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

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.

 

best

ron

View solution in original post

aandw
Level II

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

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. 

View solution in original post

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

A more direct method was added to JSL in JMP 14. Select columns, invert column selection, and delete columns can accomplish what is needed.

 

dt = open("$SAMPLE_DATA\Big Class.jmp");
a = {"height", "weight"};
dt << select columns(a);
dt << invert column selection;
b = dt << get selected columns;
dt << delete columns(b);

View solution in original post

5 REPLIES 5
txnelson
Super User

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

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

     support@jmp.com

Jim
ron_horne
Super User (Alumni)

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

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.

 

best

ron

aandw
Level II

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

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. 

msharp
Super User (Alumni)

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

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.

11841_pastedImage_1.png

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

A more direct method was added to JSL in JMP 14. Select columns, invert column selection, and delete columns can accomplish what is needed.

 

dt = open("$SAMPLE_DATA\Big Class.jmp");
a = {"height", "weight"};
dt << select columns(a);
dt << invert column selection;
b = dt << get selected columns;
dt << delete columns(b);