cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
ALopez
Level III

Concatenate a list of Tables and add a "Source Column"

I Have a list of open tables (names) that I want to concatenate and add a new “Source Column” that can be retrieved from the same list of table names. I have tried all the previous “solutions: published on this Discussion board without luck (only partial luck)

I can get my concatenated tables following a solution published by TXNelson, but I cannot seem to be able to get the “Source Column” to work.  I will appreciate any help solving this one.

tables = {"R1", "R2", "R3"};
TablesN ={};
For(k = 1, k <= n Rows ( Data Table(tables[i] )),k++, 
Insert Into(TablesN, Data Table (tables [i] ) << get name));
// the concatenation works like a charm Data Table = New Table ("RST"); For( i = 1, i <= N Items( tables ), i++, Data Table( "RST" ) << Concatenate( Data Table( tables[i] ), append to first table(1) ); //Close( Data Table( tables[i] ), No Save ); ); // this part fails
data table( "RST" ) << add multiple columns("Source Table", 1, before first, character ); :Source Table << set values( TablesN );
1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Concatenate a list of Tables and add a "Source Column"

The last part should work if the list has any values. Check out the first for loop; it uses k as iterator but inside the loop i, not defined, is used as list index.

 

A source column can also be created automatically with Concatenate() as in the example below

// Create a list of data tables
names = {"R1", "R2", "R3"};
tables = {};
For( i = 1, i <= N Items( names ), i++,
	Insert Into( tables, Data Table( names[i] ) )
);


// Concat all and create a source column in one step
dt = New Table( "RST" );
dt << concatenate( tables, append to first table( 1 ), create source column( 1 ) );

View solution in original post

4 REPLIES 4
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Concatenate a list of Tables and add a "Source Column"

The last part should work if the list has any values. Check out the first for loop; it uses k as iterator but inside the loop i, not defined, is used as list index.

 

A source column can also be created automatically with Concatenate() as in the example below

// Create a list of data tables
names = {"R1", "R2", "R3"};
tables = {};
For( i = 1, i <= N Items( names ), i++,
	Insert Into( tables, Data Table( names[i] ) )
);


// Concat all and create a source column in one step
dt = New Table( "RST" );
dt << concatenate( tables, append to first table( 1 ), create source column( 1 ) );
ALopez
Level III

Re: Concatenate a list of Tables and add a "Source Column"

Hi MS,

I tested your code:

dt = New Table( "RST" );
dt << concatenate( tables, append to first table( 1 ), create source column( 1 ) );

and it creates a pop up window that would allow me to select the tables to concatenate, which defeats the purpose of creating a script to automate the process.  It does not iterate through the "tables" list.  I am using JMP 15 .
Just FYI, this is the post that I have been using to guide me. Thanks.
https://community.jmp.com/t5/Discussions/JSL-bug-Concatenate-all-opened-table-into-1-table-and-close...

 

ms
Super User (Alumni) ms
Super User (Alumni)

Re: Concatenate a list of Tables and add a "Source Column"

The list tables must contain data table objects (first part of my code illustrate one way do create such a list) and all tables must still be open when the code is run. Otherwise you'll get the pop-ip window. 

After the code is run, you can close all (saved) data tables in the list in one step with tables << close window;.

 

 

ALopez
Level III

Re: Concatenate a list of Tables and add a "Source Column"

@ms - Yes, I had the "names" not the objects. Thank you very much for taking the time to help me.
Best regards,
Alfredo