Choose Language Hide Translation Bar
Highlighted
Stokes
Level III

[JSL bug] Concatenate all opened table into 1 table and close all

Can someone help me to take a look bellow jsl?

I am trying to use it concatenate all open table into a single table, and close all the open table, only leave a final table which was concatenated from all of them.

When I run the jsl, it has a bug to re-produce multiple "final" table and not concatenate into 1 single table.

Not clear where the bug is coming from.

Thanks

 

 

Clear Globals();

// Create your Tables list
Tables = {};
For( i = 1, i <= N Table(), i++,
    Insert Into( Tables, Data Table( i ) << get name )
);

// Run the concatinations
For( i = 1, i < N Items( Tables ), i++,
    ConcTable = Data Table( Tables[i] ) << Concatenate(
        Data Table( Tables[i + 1] ),
        Create source column,
        Output Table Name( "final" )
    );
    Close( Data Table( Tables[i] ), No Save );
);

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

Re: [JSL bug] Concatenate all opened table into 1 table and close all

Doing what you want to do, if you didn't want the Source Table Column, is very simple

Names Default To Here( 1 );
Clear Globals();

// Create your Tables list
Tables = {};
For( i = 1, i <= N Table(), i++,
	Insert Into( Tables, Data Table( i ) << get name );
);

new Table("all data");
// Run the concatinations
For( i = 1, i <= N Items( Tables ), i++,
	 Data Table( "all data" ) << Concatenate(
		Data Table( Tables[i] ),
		append to first table(1)
	);
	Close( Data Table( Tables[i] ), No Save );
);

It gets more complex if you want a Source Table.  Using the built in option of "Create Source Column", will produce a new Source Table column for each concatenation you do.  So some adjustments need to be made.  Below is a working script that should give you what you want

Names Default To Here( 1 );
Clear Globals();

// Create your Tables list
Tables = {};
TablesN = {};
For( i = 1, i <= N Table(), i++,
	Insert Into( Tables, Data Table( i ) << get name );
	for(k=1,k<=n rows(data table(i)),k++, insert into(TablesN,data table( i ) << get name));
);

new Table("all data");
// Run the concatinations
For( i = 1, i <= N Items( Tables ), i++,
	 Data Table( "all data" ) << Concatenate(
		Data Table( Tables[i] ),
		append to first table(1)
	);
	Close( Data Table( Tables[i] ), No Save );
);
 
 data table( "all data" ) << add multiple columns("Source Table", 1, before first, character );
:Source Table << set values( TablesN );
Jim

View solution in original post

4 REPLIES 4
Highlighted
txnelson
Super User

Re: [JSL bug] Concatenate all opened table into 1 table and close all

Doing what you want to do, if you didn't want the Source Table Column, is very simple

Names Default To Here( 1 );
Clear Globals();

// Create your Tables list
Tables = {};
For( i = 1, i <= N Table(), i++,
	Insert Into( Tables, Data Table( i ) << get name );
);

new Table("all data");
// Run the concatinations
For( i = 1, i <= N Items( Tables ), i++,
	 Data Table( "all data" ) << Concatenate(
		Data Table( Tables[i] ),
		append to first table(1)
	);
	Close( Data Table( Tables[i] ), No Save );
);

It gets more complex if you want a Source Table.  Using the built in option of "Create Source Column", will produce a new Source Table column for each concatenation you do.  So some adjustments need to be made.  Below is a working script that should give you what you want

Names Default To Here( 1 );
Clear Globals();

// Create your Tables list
Tables = {};
TablesN = {};
For( i = 1, i <= N Table(), i++,
	Insert Into( Tables, Data Table( i ) << get name );
	for(k=1,k<=n rows(data table(i)),k++, insert into(TablesN,data table( i ) << get name));
);

new Table("all data");
// Run the concatinations
For( i = 1, i <= N Items( Tables ), i++,
	 Data Table( "all data" ) << Concatenate(
		Data Table( Tables[i] ),
		append to first table(1)
	);
	Close( Data Table( Tables[i] ), No Save );
);
 
 data table( "all data" ) << add multiple columns("Source Table", 1, before first, character );
:Source Table << set values( TablesN );
Jim

View solution in original post

Highlighted
Stokes
Level III

Re: [JSL bug] Concatenate all opened table into 1 table and close all

This is great, thanks Jim.

Highlighted
gzmorgan0
Super User

Re: [JSL bug] Concatenate all opened table into 1 table and close all

@Stokes,

 

The script you posted is creating  a bunch of new tables.  Community note: I do not know if there is a syntax to close a list of data tabes, hence, the For Loop is used to close the source tables one at a time, by name, not number. 

Names Default to Here(1);

//Careful, this closes all data tables

close all(Data Tables);
//now create similar looking tables

dt = Open("$Sample_Data/Big Class.jmp");

dt << Subset( By (:age));

//close Big Class, keep all the age subset tables open
close(dt,NoSave);

// Create your Tables list
nt = N Table();
Tables = {};
For( i = 1, i <= nt, i++,
	Insert Into( Tables, Eval Expr( Data Table( Expr( Data Table( i ) << get name ) ) ) )
);
final = Concatenate( Tables, Create Source Column, Output Table Name( "Big Class Redux" ) );

//close all in the list
For( i = 1, i <= nt, i++,
	Eval( Eval Expr( Close( Expr( Tables[i] ), NoSave ) ) )
);

 

Highlighted
gzmorgan0
Super User

Re: [JSL bug] Concatenate all opened table into 1 table and close all

Oops, sorry Jim,  @txnelson , I didn't see your response.

 

 

Article Labels