cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
Theresa
Level IV

How to select rows with 2 different data table with matched column

&*script below don't work could you help to debug and send me a workable script? I want to realize the function that "select all rows" in dt which matched column: name in dt1.

dt = Open( "$SAMPLE_DATA/BIG CLASS.JMP" );
dt1 = dt << Subset( Columns( Name ), Output Table Name( "1" ) );
dt1 << Delete Rows( 15 :: 40 ); // I want to relize the function of "select all rows that (dt:name==dt1:name) dt << Select where( With(dt1), By Matching Columns(name==name), );
;
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How to select rows with 2 different data table with matched column

Here are 3 different ways to do this.....and I am sure others may have other ways to do this

names default to here(1);

dt = Open( "$SAMPLE_DATA/BIG CLASS.JMP" );
dt1 = dt << Subset( Columns( Name ), Output Table Name( "1" ) );
dt1 << Delete Rows( 15 :: 40 ); 

// Method one, read a name in dt1 and select it in dt, repeat 
// for all rows in dt1

dt << clear rowstates;

For(i=1,i<= nrows(dt1),i++,
	dt << select where(dt:name == dt1:name[i], current selection("extend"));
);

// Method 2, extract names from dt1 into a list, and then
// compare against the list for the 

dt << clear rowstates;

nameList = dt1:name << get values;
dt << select where(contains(nameList,:name));

//Method 3, Update dt with dt1 and select matching rows
// this method would be the fastest on large data tables

dt << clear rowstates;

// add a column to use as a selector
dt1 << New Column( "selector", set each value( 1 ) );

dt << Update( With( dt1 ), Match Columns( :name = :name ) );
dt << select where( :selector == 1 );
dt << delete columns( "selector" );
dt1 << delete columns( "selector" );
Jim

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: How to select rows with 2 different data table with matched column

Here are 3 different ways to do this.....and I am sure others may have other ways to do this

names default to here(1);

dt = Open( "$SAMPLE_DATA/BIG CLASS.JMP" );
dt1 = dt << Subset( Columns( Name ), Output Table Name( "1" ) );
dt1 << Delete Rows( 15 :: 40 ); 

// Method one, read a name in dt1 and select it in dt, repeat 
// for all rows in dt1

dt << clear rowstates;

For(i=1,i<= nrows(dt1),i++,
	dt << select where(dt:name == dt1:name[i], current selection("extend"));
);

// Method 2, extract names from dt1 into a list, and then
// compare against the list for the 

dt << clear rowstates;

nameList = dt1:name << get values;
dt << select where(contains(nameList,:name));

//Method 3, Update dt with dt1 and select matching rows
// this method would be the fastest on large data tables

dt << clear rowstates;

// add a column to use as a selector
dt1 << New Column( "selector", set each value( 1 ) );

dt << Update( With( dt1 ), Match Columns( :name = :name ) );
dt << select where( :selector == 1 );
dt << delete columns( "selector" );
dt1 << delete columns( "selector" );
Jim
ezorlo
Level IV

Re: How to select rows with 2 different data table with matched column

this is really nice! I used method 1.

I needed to copy-paste the file path of my data table for this to work. i couldnt figure out how to change the working directory so that I could just type in the file names without the whole path.

 

Theresa
Level IV

Re: How to select rows with 2 different data table with matched column

thank you so much