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
Jackie_
Level VI

Delete string that does not contain in the list

Hi,

 

I'm trying to write a jsl code that removes numbers from a row if they are not present in a given list.

 

The list is in the table call "List values"

Jackie__0-1683732684980.png

 

Bins values I want to modify:

Jackie__2-1683732697543.png

For example: the jsl script should delete "444" from row 7 in the above table and likewise for other rows

Final result:

Jackie__0-1683733281145.png

 

Here's the code

Names Default To Here( 1 );
dt_list =  Data Table("List values");
dtt = Data Table("Bins");
list = dt_list:List<< get values;

//Loop through rows to find the number contain in the lis
For( i = 6, i <= N rows( dtt ), i++,

if( !contains(list, Words( dtt:Bins[i], "[  ]" )),
		
	// I am not sure how to proceed further?	
		
		
	););

Any suggestions?

 

Thanks,

Jackie

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Delete string that does not contain in the list

If it doesn't matter that the order is changed, using Associative Arrays is one option

Names Default To Here(1);

dt1 = Open("$DOWNLOADS/List values.jmp");
Column(dt1, "List") << Data Type("Numeric");
dt2 = Open("$DOWNLOADS/Bins.jmp");

aa_listvalues = Associative Array(Column(dt1, "List"));

dt2 << New Column("BinsList", Character, Nominal, << Set Each Value(
	If(!IsMissing(:Bins),
		r_aa = Associative Array(Parse(:Bins));
		r_aa << Intersect(aa_listvalues);
		If(N Items(r_aa) > 0,
			Substitute(Char((r_aa << get keys)), "}", "]", "{", "[", ",", " ");
		,
			""
		);
	,
		""
	);
));

Not sure why 410 wouldn't be removed on Row 10

jthi_0-1683734756948.png

 

-Jarmo

View solution in original post

2 REPLIES 2
jthi
Super User

Re: Delete string that does not contain in the list

If it doesn't matter that the order is changed, using Associative Arrays is one option

Names Default To Here(1);

dt1 = Open("$DOWNLOADS/List values.jmp");
Column(dt1, "List") << Data Type("Numeric");
dt2 = Open("$DOWNLOADS/Bins.jmp");

aa_listvalues = Associative Array(Column(dt1, "List"));

dt2 << New Column("BinsList", Character, Nominal, << Set Each Value(
	If(!IsMissing(:Bins),
		r_aa = Associative Array(Parse(:Bins));
		r_aa << Intersect(aa_listvalues);
		If(N Items(r_aa) > 0,
			Substitute(Char((r_aa << get keys)), "}", "]", "{", "[", ",", " ");
		,
			""
		);
	,
		""
	);
));

Not sure why 410 wouldn't be removed on Row 10

jthi_0-1683734756948.png

 

-Jarmo
Jackie_
Level VI

Re: Delete string that does not contain in the list

Thank a lot, Jarmo!

Forget to delete 410