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
saneal
Level III

Check if wafer from an input string is contained within a data table

I have an input string from below: 

For( i = 1, i <= N Rows( dtWaferIDList ), i++,
	tempi = Column( dtWaferIDList, 1 )[i];
	InputString = If( i == 1, "'", "" ) || InputString || tempi || If( i < N Rows( dtWaferIDList ), "','", "'" );
);

And a table1 that I pull from a database. I would like to check to see if (in the Wafer column of table 1) all the wafers from the input string are contained in that column. 

- if all wafers have data: display message = "data for all wafers available".

- if not: display message = "no data available".

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Check if wafer from an input string is contained within a data table

Use debug Show()s and small data set to test where you go wrong (open log window from View / Log).

 

Maybe this will help you forward:

Names Default To Here(1);
dt1 = Open("$SAMPLE_DATA/Big Class.jmp");
dt1 << Select Rows([1,2,3]);
dt2 = dt1 << Subset(selected rows);
dt1 << clear select;

dt1_uniq = Associative Array(dt1:name);
dt2_uniq = Associative Array(dt2:name);
dt1_copy = dt1_uniq;
dt2_copy = dt2_uniq;
dt1_copy << Remove(dt2_copy);

Show(concat items(dt1_uniq << get keys, ", "));
Show(concat items(dt2_uniq << get keys, ", "));
Show(concat items(dt1_copy << get keys, ", "));
Show(N Items(dt1_uniq), N Items(dt2_uniq), N Items(dt1_copy));
-Jarmo

View solution in original post

9 REPLIES 9
jthi
Super User

Re: Check if wafer from an input string is contained within a data table

You could most likely use Associative Array for this comparison Applications for Associative Arrays . Check out the part  Compare Columns in Two Different Data Tables

-Jarmo
txnelson
Super User

Re: Check if wafer from an input string is contained within a data table

@jthi has pointed you in the right direction.  Your proposed approach is using a very long literal string.  I suggest that you either use associative arrays, or a JMP list.  

Below is a simple script that opens a data table that contains wafers.  It then creates a data table that has a random set of wafers.  Finally it checks to see if the random set contains all wafers from the first data table.

names default to here(1);
// Open Data Table: semiconductor capability.jmp
// ā†’ Data Table( "semiconductor capability" )
dt = Open( "$SAMPLE_DATA/semiconductor capability.jmp" );

unique wafers = associative array(dt:Wafer);

// Create a random wafer table and see if it contains all wafers
dtRand = new table("Random",
	add rows(60),
	new column("Rand Wafer", set each value(random integer(1,24)));
);

random wafers = associative array(dtRand:Rand wafer);
Random wafers << Intersect( unique wafers );

if(n items(Random wafers) == n items( unique wafers),
   msg = "data for all wafers available",
   msg = "no data available"
 );

new window("Message", <<modal,
	text box(msg)
);
Jim
saneal
Level III

Re: Check if wafer from an input string is contained within a data table

Hello Nelson,

 

I appreciate the help! I am a bit new to JMP still and haven't used Associative Arrays at all yet. I have read up on it on the scripting guide and index; but am still having some confusion. Here is where I am at in my code: (directly after opening the table WaferRgDt from a database)

unique wafers = Associative Array( WaferRgDt:Wafer );
given wafers = Associative Array( dtWaferIDList:WaferList );
intersection = unique wafers; intersection << Intersect( given wafers); //intersection between arrays

//uncommmon2 represents wafers that have no data associated with it.
uncommon2 = given wafers; uncommon2 <<remove(intersection); show(uncommon2 << Get Keys);

if(n items( given wafers ) == n items( unique wafers ),
   msg = "Data for all wafers is available.",
   //else
   msg = Write("\!N#Data is unavailable for the following wafers:", uncommon2 << Get Keys)
 );

new window("Message", <<modal,
	text box(msg)
);

When I run this I get an empty messagebox with a period... so something seems wrong still. Wondering if its a logic issue or syntax. I have had some trouble finding how to write keys in a messagebox if its even possible to do. Hope that was clear enough. Thanks again!

 

saneal
Level III

Re: Check if wafer from an input string is contained within a data table

Also used this discussion post to aid in writing the code aboveRe: Quick way to compare two lists (uncommon elements)? 

jthi
Super User

Re: Check if wafer from an input string is contained within a data table

To convert a list of strings into a string you can use Concat Items()

Names Default To Here(1);
aa = Associative Array({"bun",
	"shoe",
	"tree",
	"door"}
);

uniqKeys = aa << get keys;
Show(uniqKeys);
Show(Concat Items(uniqKeys, ", "));

 

-Jarmo
saneal
Level III

Re: Check if wafer from an input string is contained within a data table

@jthi 

I don't see how that solves my particular issue. When I run your script, nothing happens. I need the keys from the associative array to be visible to the user and displayed in a msg box.

unique wafers = Associative Array( WaferRgDt:Wafer );
given wafers = Associative Array( dtWaferIDList:WaferList );
intersection = unique wafers; intersection << Intersect( given wafers); //intersection between arrays

//uncommon represents wafers that have no data associated with it.
uncommon = given wafers; uncommon2 <<remove(intersection); show(uncommon << Get Keys);

if(n items( given wafers ) == n items( unique wafers ),
   msg = "Data for all wafers is available.",
   //else
   msg = Show(Concat Items("\!N#Data is unavailable for the following wafers:", uncommon << Get Keys))
 );

new window("Message", <<modal,
	text box(msg)
);
jthi
Super User

Re: Check if wafer from an input string is contained within a data table

Use debug Show()s and small data set to test where you go wrong (open log window from View / Log).

 

Maybe this will help you forward:

Names Default To Here(1);
dt1 = Open("$SAMPLE_DATA/Big Class.jmp");
dt1 << Select Rows([1,2,3]);
dt2 = dt1 << Subset(selected rows);
dt1 << clear select;

dt1_uniq = Associative Array(dt1:name);
dt2_uniq = Associative Array(dt2:name);
dt1_copy = dt1_uniq;
dt2_copy = dt2_uniq;
dt1_copy << Remove(dt2_copy);

Show(concat items(dt1_uniq << get keys, ", "));
Show(concat items(dt2_uniq << get keys, ", "));
Show(concat items(dt1_copy << get keys, ", "));
Show(N Items(dt1_uniq), N Items(dt2_uniq), N Items(dt1_copy));
-Jarmo
txnelson
Super User

Re: Check if wafer from an input string is contained within a data table

Your msg value is being specified incorrectly.  The below will work

msg = "\!N#Data is unavailable for the following wafers:" || Char( uncommon2 << Get Keys );
Jim
saneal
Level III

Re: Check if wafer from an input string is contained within a data table

Thank you both! Looks to be working now. I appreciate it!