cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
UserID16644
Level V

Search and select word on string

Hi all,

 

I have two different data tables, and I need to find and select if the word exist on the other table.

I tried using Contains() but is not working. Please help

 

Here is an example:

dt1                              

dog
cat
fish
bird
cow

 

dt2

dog&gorilla
mouse, giraffe
shark, whale, penguin
ostrich&bird
lion&tiger,cow

 

 

Result (text in bold characters are selected): 

dt2

dog&gorilla
mouse, giraffe
shark, whale, penguin
ostrich&bird
lion&tiger,cow
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Search and select word on string

Here is one way to do what you are looking for.  Please note, I believe your table that shows the results has row 3 incorrectly selected.

Names Default To Here( 1 );

// Create the tables
dt1 = New Table( "Lookup", Add Rows( 5 ), New Column( "key", Character, Set Values( {"dog", "cat", "fish", "bird", "cow"} ) ) );
dt2 = New Table( "Base",
	Add Rows( 5 ),
	New Column( "Target", Character, Set Values( {"dog&gorilla", "mouse, giraffe", "shark, whale, penguin", "ostrich&bird", "lion&tiger,cow"} ) )
);

// Place all key values into a list
KeyList = dt1:key << get values;

// Loop across the keys and search each row of Target for the 
// match
For Each( {val}, keyList,
	For Each Row(
		If( Contains( :Target, val ),
			Row State( Row() ) = Selected State( 1 )
		)
	)
);

txnelson_0-1709611455018.png

 

Jim

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: Search and select word on string

Here is one way to do what you are looking for.  Please note, I believe your table that shows the results has row 3 incorrectly selected.

Names Default To Here( 1 );

// Create the tables
dt1 = New Table( "Lookup", Add Rows( 5 ), New Column( "key", Character, Set Values( {"dog", "cat", "fish", "bird", "cow"} ) ) );
dt2 = New Table( "Base",
	Add Rows( 5 ),
	New Column( "Target", Character, Set Values( {"dog&gorilla", "mouse, giraffe", "shark, whale, penguin", "ostrich&bird", "lion&tiger,cow"} ) )
);

// Place all key values into a list
KeyList = dt1:key << get values;

// Loop across the keys and search each row of Target for the 
// match
For Each( {val}, keyList,
	For Each Row(
		If( Contains( :Target, val ),
			Row State( Row() ) = Selected State( 1 )
		)
	)
);

txnelson_0-1709611455018.png

 

Jim
UserID16644
Level V

Re: Search and select word on string

Just a follow up question, can I use this selected rows in matching to other tables? Like in Update?

txnelson
Super User

Re: Search and select word on string

I am not understand your question.  However, you can easily create a subset of the base table that contains just the selected rows, and then you can update another table from that table.  Here is the JSL to do the subsetting

dt3 = dt2 << Subset( selected columns( 0 ), selected rows( 1 ) );
Jim