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
JMPnoob
Level II

Combining data tables if number of opened tables varies

Hello,

I have a script that gets items chosen by the user from a list box. Based on the number of items selected by the user, a number of tables pop up. The number of new data tables is variable and I would like to combine them all into one larger table called Combined Table. I know the concatenate function does this, but I would like to have it scripted to accommodate a user specified number of tables.

 

From this piece of code, a number of new tables pop up named EachChem, EachChem 2, EachChem 3...ectc. I would like to combine those into a larger table called Combined Table. 

 

For (i = 1, i <= N Items(lt), i++,	  
	   
	    dt << Select Where( :chemical == lt[i] );
	    dt << Get selected rows
	    dt << Subset(Output Table("EachChem"), Selected Rows(i));
    );
      

 

Alternative, if I could combined the tables within the above for loop, and end up with one large subset table called EachChem, that would be good too.

 

Any help or pointers is appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Combining data tables if number of opened tables varies

This should do what you want

theExpr = "Data Table( \!"EachChem\!") << Concatenate(";
For( i = 2, i <= N Items( lt ), i++,
	theExpr = theExpr || " Data Table( \!"EachChem " || Char( i ) || "\!"),"
);
theExpr = theExpr || "Output Table( \!"Combined Table\!" ) );";

Eval( Parse( theExpr ) );
Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: Combining data tables if number of opened tables varies

This should do what you want

theExpr = "Data Table( \!"EachChem\!") << Concatenate(";
For( i = 2, i <= N Items( lt ), i++,
	theExpr = theExpr || " Data Table( \!"EachChem " || Char( i ) || "\!"),"
);
theExpr = theExpr || "Output Table( \!"Combined Table\!" ) );";

Eval( Parse( theExpr ) );
Jim
JMPnoob
Level II

Re: Combining data tables if number of opened tables varies

Thanks. This worked.

 

If the names of the tables to be concatenated also changes, the following should work.

 

 

theExpr = " Data Table( \!"" || MaskList[1] || " " || Char( 2 ) || "\!") << Concatenate(";
For( i = 2, i <= N Items(MaskList), i++,
	theExpr = theExpr || " Data Table( \!"" || MaskList[i] || " " || Char( 2 ) || "\!"),"
);
theExpr = theExpr || "Output Table( \!"Final Table\!" ) );";
Eval( Parse( theExpr ) );

In the code above,

 

MaskList is a list that holds a variable number of masks depending on the user. There are tables associated with each mask in MaskList.

 

For example, the first table is called Mask1 2, (the second table with the name called Mask1, hence the extra 2) the next table to be concatenated is called Mask9 2. (the second table with the name called Mask9, hence the extra 2) and so on.

 

This will concatenate, Mask1 2 with Mask9 and so on.

 

Just putting this here for documentation purposes.