Subscribe Bookmark RSS Feed

Concatenate Tables and close the input files

Christian

Community Trekker

Joined:

Jun 2, 2014

I am looking for a way to close the tables that are open and have served for input

 

For( f2 = 1, f2 < N Items( Tables ), f2++,
        ConcTable = Tables[f2] <<  /*###*/Concatenate(
            Tables[f2 + 1],
            Output Table Name( "Both" )
        ) /*###*/;
        Close( filelist[f2], No Save );
    );

 

The answer in the log is:

 

Send Expects Scriptable Object in access or evaluation of 'Send' , Tables[f2] <<  /*###*/Concatenate( Tables[f2 + 1], Output Table Name( "Both" ) ) /*###*/

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson

Super User

Joined:

Jun 22, 2012

Solution

here is a simple method to concatenate the tables, and close those not needed

Names Default To Here( 1 );
Final_Table="Data_" || char(ntable);
// Concatenate the tables and delete them.  Add all of the tables to the first table
dt-data table(1);
For( i = 2, i <= N Table(), i++,
	dt << concatenate(data table(i), append to first table(1));
	close(data table(i), nosave);
);
// Rename the table to the desired name
dt << set name(Final_Table);
Jim
5 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

Here is a piece of code that will work, and follows the logic of what you have specified.  However, I don't understand why you would want to do this.......so maybe the result will not be what you are imagining.  If not reply with what the end result is supposed to be.

Names Default To Here( 1 );

// Create sample tables
dt = Open( "$SAMPLE_DATA\big class.jmp" );
dt << subset( selected rows( 0 ), selected columns( 0 ), by( :age ) );
Close( dt, nosave );

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

// Run the concatinations
For( f2 = 1, f2 < N Items( Tables ), f2++,
	ConcTable = Data Table( Tables[f2] ) << Concatenate( Data Table( Tables[f2 + 1] ), Output Table Name( "Both" ) );
	Close( Data Table( Tables[f2] ), No Save );
);
Jim
Christian

Community Trekker

Joined:

Jun 2, 2014

Jim, thanks for the answer. Let me expand a little further. Goal is to concatenate a list of data tables and to delete double rows. Any data tables that have contributed to the final concatenated table to be closed. The number of input data tables is variable. The selection of the datatbales to be concatenated is following the rule that the beginning strings are equal and the final name of the concatenated data table is the same string.

 

Here now the code for concatenation and double row deletion plus saving the final table.

 

If(N Items(filelist)>0,

for    (nu_t = 1, nu_t <= num_tables, nu_t++,                

FinalTable  = Munger(filelist[1],6,4);
Final_Table = "Data_"||FinalTable||".jmp";
//Show(FinalTable);
for    (f2 = 1, f2 < nitems(Tables), f2++,
    ConcTable = Tables[f2] << Concatenate(Tables[f2+1], Output Table Name( "Both" ) );
    Close( Tables[f2] , No Save );
    );
    // Delete Doube Rows
    ConcTable = Current Data Table();
    col_min = Parse( "Col Min( Row(), :Name(\!"" || Concat Items( ConcTable << get column names( string ), "\!"), :Name(\!"" ) || "\!"))" );
    duplicates = [];
    For Each Row( If( col_min != Row(), duplicates |/= Row() ) );
    ConcTable << delete rows( duplicates );

ConcTable << Save(Path_datatable_out||Final_Table);

//For(cc=1,cc <= nitems(Tables),cc++, Close(Tables[cc], No Save));
);
); // If Condition

 

I am looking forward for your reply.

 

Christian

 

txnelson

Super User

Joined:

Jun 22, 2012

Can you please supply a sample of you data tables, and an illustration of what would be considered duplicate rows?

Jim
Christian

Community Trekker

Joined:

Jun 2, 2014

Jim,

 

If you look in the two attched table, they have the same number of columns and column names. The only thing that differentiate both is the number of rows. Column #1 is the time stamp and based on this duplicates will be removed.

 

The method as scripted works. I am looking for an efficent way of saving the final table and close the tables that have been the input for the final.

 

Best regards,

Christian

txnelson

Super User

Joined:

Jun 22, 2012

Solution

here is a simple method to concatenate the tables, and close those not needed

Names Default To Here( 1 );
Final_Table="Data_" || char(ntable);
// Concatenate the tables and delete them.  Add all of the tables to the first table
dt-data table(1);
For( i = 2, i <= N Table(), i++,
	dt << concatenate(data table(i), append to first table(1));
	close(data table(i), nosave);
);
// Rename the table to the desired name
dt << set name(Final_Table);
Jim