cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
Sean_ShCn0
Level II

how to use contains for mutiple charators selection and subset ?

I wrote a script for the following purpose:

  1. for "chart" column, i want select all items which contains mutiple charators like:" Trace width","Trace thickness","insulator thickness" , actually i have more to be selected, but in jsl which i worte just take 3 charators. I take 6 rows to take them one by one, and subset them to 3 new tables. that is a a little complex, any ideas to set only one row script like OR() or ORMZ(), i tried, but failed. the script works, but seems to stupid.-_-!!!
  2. second question, in the subset rows, i have set output talbe("TT"), means i want to name the new subset talbe, but actually the new table name is not change, how i can write the script for it ?
Names Default To Here(1);
IM = Open("$DESKTOP/sample table.jmp" );
IM <<select where(contains (:Chart,"Trace thickness"));
dt=IM<<subset(Rows(IMP),selected rows(0),output table ("TT"));

IM <<select where(contains (:Chart,"Trace width"));
dt=IM<<subset(Rows(IMP),selected rows(0),output table ("TW"));

IM <<select where(contains (:Chart,"Insulator thicknes"));
dt=IM<<subset(Rows(IMP),selected rows(0),output table ("InT"));

Data Table( "Subset of sample table" ) << Concatenate(
	Data Table( "Subset of sample table 2" ),
	Data Table( "Subset of sample table 3" ),
	Output Table( "IMP table" )
);
2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: how to use contains for mutiple charators selection and subset ?

You could use Or and multiple contains statements, Substitute to replace those strings and check for length or use Regex. Here are examples for substitute and regex (substitute is most likely faster)

Names Default To Here(1);

dt = Open("$DOWNLOADS/sample table.jmp");
dt << select where(Length(:Chart) > Length(Substitute(:Chart, {"Trace thickness", "Trace width", "Insulator thicknes"}, {"", "", ""})));
// dt << select where(!Is Missing(Regex(:Chart, "Trace thickness|Trace width|Insulator thicknes")));

dt_subset = dt << Subset(Selected Rows, Selected Columns Only(0), Output Table("Subset"));

 

-Jarmo

View solution in original post

jthi
Super User

Re: how to use contains for mutiple charators selection and subset ?

You can use the Replace String in Recode

jthi_1-1723142986444.png

 

jthi_0-1723142823838.png

And in this case it seems to be able to even create working

Local({dt, col1},
	dt = Data Table("Subset");
	dt << Begin Data Update;
	col1 = dt << New Column(dt:Chart);
	col1 << Set Name("Chart 2");
	dt << Move Selected Columns({col1}, after(dt:Chart));
	For Each Row(
		dt,
		col1[] = If(Contains(dt:Chart, "Trace thickness"),
			"TT",
			dt:Chart
		)
	);
	dt << End Data Update;
);

You can slightly modify it if you wish to

Names Default To Here(1);

dt = Open( "$DOWNLOADS/sample table.jmp" );
dt << select where(Length(:Chart) > Length(Substitute(:Chart, {"Trace thickness", "Trace width", "Insulator thicknes"}, {"", "", ""})));


dt_subset = dt << Subset(Selected Rows, Selected Columns Only(0), Output Table("Subset"));

dt_subset << Begin Data Update;
For Each Row(
	dt_subset,
	:Chart = If(Contains(dt:Chart, "Trace thickness"),
		"TT",
		dt:Chart
	)
);
dt_subset << End Data Update;
-Jarmo

View solution in original post

5 REPLIES 5
jthi
Super User

Re: how to use contains for mutiple charators selection and subset ?

You could use Or and multiple contains statements, Substitute to replace those strings and check for length or use Regex. Here are examples for substitute and regex (substitute is most likely faster)

Names Default To Here(1);

dt = Open("$DOWNLOADS/sample table.jmp");
dt << select where(Length(:Chart) > Length(Substitute(:Chart, {"Trace thickness", "Trace width", "Insulator thicknes"}, {"", "", ""})));
// dt << select where(!Is Missing(Regex(:Chart, "Trace thickness|Trace width|Insulator thicknes")));

dt_subset = dt << Subset(Selected Rows, Selected Columns Only(0), Output Table("Subset"));

 

-Jarmo
Sean_ShCn0
Level II

Re: how to use contains for mutiple charators selection and subset ?

it works, and with high effience. thanks very much!

Sean_ShCn0
Level II

Re: how to use contains for mutiple charators selection and subset ?

Hi Jarmo,

 

I have further question on Recode, i want recode by chart , filter all the charater when there are "Trace thickness" characters in name, i need recode them to new name "TT"

i have a script but same qustion ,it is not good. Could you also help to check if have better solution for it ? Thanks a lot!   KRs Sean

Names Default To Here(1);

dt = Open( "$DESKTOP/sample table.jmp" );
dt << select where(Length(:Chart) > Length(Substitute(:Chart, {"Trace thickness", "Trace width", "Insulator thicknes"}, {"", "", ""})));


dt_subset = dt << Subset(Selected Rows, Selected Columns Only(0), Output Table("Subset"));

// Recode column: Category
dt = Data Table( "Subset" );
dt << Begin Data Update;
col1 = dt << New Column( dt:Chart );
col1 << Set Name( "Category" );
dt << Move Selected Columns( {col1}, after( dt:Chart ) );
dt << Recode Column(
	dt:Chart,
	{Map Value(
		_rcOrig,
		{"B 1B 110um Trace thickness", "TT", "B 2B 18um Trace thickness", "TT",
		"B 2F 15um Trace thickness", "TT", "B 2F 24um Trace thickness,DE D", "TT",
		"B 2F 32um Trace thickness,SE6", "TT", "B 3B 90um Trace thickness", "TT",
		"B 3F 90um Trace thickness", "TT", "B 4B 18um Trace thickness", "TT",
		"B 4F 13um Trace thickness,DE B", "TT", "B 4F 15um Trace thickness", "TT",
		"B 4F 18um Trace thickness,DE B", "TT", "B 4F 24um Trace thickness,DE C",
		"TT", "B 4F 30um Trace thickness,DE C", "TT",
		"B 4F 32um Trace thickness,SE6", "TT", "B 4F 35.5um Trace thickness,SE6",
		"TT", "B 4F 41um Trace thickness,SE2", "TT",
		"B 4F 44.5um Trace thickness,SE2", "TT", "B 5B 90um Trace thickness", "TT",
		"B 5F 90um Trace thickness", "TT", "B 6B 18um Trace thickness", "TT",
		"B 6F 13.5um Trace thickness,SE5", "TT", "B 6F 14um Trace thickness", "TT",
		"B 6F 15um Trace thickness,SE2 L2", "TT", "B 6F 15um Trace thickness,SE5",
		"TT", "B 6F 17um Trace thickness,SE4", "TT", "B 6F 18.5um Trace thickness",
		"TT", "B 6F 20um Trace thickness,SE3", "TT", "B 6F 20um Trace thickness,SE4",
		"TT", "B 6F 41um Trace thickness,SE2 L1", "TT",
		"B 6F 44.5um Trace thickness,SE2 L1", "TT", "B 7B 85um Trace thickness",
		"TT", "B 7F 14um Trace thickness", "TT", "B 8B 18um Trace thickness", "TT",
		"B 8F 14um Trace thickness", "TT", "B 8F 18um Trace thickness,SE1", "TT",
		"B 8F 28.5um Trace thickness,DE A", "TT", "B 8F 30.5um Trace thickness,SE5",
		"TT", "B 9B 90um Trace thickness", "TT", "B 9F 14um Trace thickness", "TT"},
		Unmatched( _rcNow )
	)},
	Update Properties( 1 ),
	Target Column( col1 )
);
dt << End Data Update;

 

 

jthi
Super User

Re: how to use contains for mutiple charators selection and subset ?

You can use the Replace String in Recode

jthi_1-1723142986444.png

 

jthi_0-1723142823838.png

And in this case it seems to be able to even create working

Local({dt, col1},
	dt = Data Table("Subset");
	dt << Begin Data Update;
	col1 = dt << New Column(dt:Chart);
	col1 << Set Name("Chart 2");
	dt << Move Selected Columns({col1}, after(dt:Chart));
	For Each Row(
		dt,
		col1[] = If(Contains(dt:Chart, "Trace thickness"),
			"TT",
			dt:Chart
		)
	);
	dt << End Data Update;
);

You can slightly modify it if you wish to

Names Default To Here(1);

dt = Open( "$DOWNLOADS/sample table.jmp" );
dt << select where(Length(:Chart) > Length(Substitute(:Chart, {"Trace thickness", "Trace width", "Insulator thicknes"}, {"", "", ""})));


dt_subset = dt << Subset(Selected Rows, Selected Columns Only(0), Output Table("Subset"));

dt_subset << Begin Data Update;
For Each Row(
	dt_subset,
	:Chart = If(Contains(dt:Chart, "Trace thickness"),
		"TT",
		dt:Chart
	)
);
dt_subset << End Data Update;
-Jarmo
Sean_ShCn0
Level II

Re: how to use contains for mutiple charators selection and subset ?

Thanks, Jarmo, thanks a lot. It works and help me to generate ideas. 

 

KR 

Sean