cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar

Concatenate all data tables using JSL

Hi, I want to concatenate all open data tables. However, the number of data tables can vary and I want the script to be able to adapt for different number of tables.

 

This is the code for what I want to do, however I want to have it generalised:

 
Data Table(N Table()) << Concatenate(
	Data Table((N Table() - 1)),
	Data Table((N Table() - 2)),
	Data Table((N Table() - 3)),
	Data Table((N Table() - 4)),
	Data Table((N Table() - 5)),
	Output Table("All Temps"),
	Create source column
);
 
This is code I have tried, an error of unresolved name of output table occurs ( in this case noTemps is 6 )

Data Table(N Table()) << Concatenate(
	For(i = 1, i < (noTemps), i++,
		Data Table((N Table() - i)),

	);
	Output Table("All Temps");,
	Create source column
);
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Concatenate all data tables using JSL

If JMP16+ I would use for each and loop over the list of tables

Names Default To Here(1);

dt1 = Open("$SAMPLE_DATA/Big Class.jmp");
dt2 = dt1 << Subset(All Rows, Selected Columns(0), Output Table("DEMO"));

dts = Get Data Table List();

dt_first = Remove From(dts, 1); // remove first table as we concatenate to that

For Each({dt}, dts,
	dt_first << Concatenate(
		dt,
		"Append to first table",
		"Create source column"
	);
	// Close(dt, no save);
);
-Jarmo

View solution in original post

6 REPLIES 6
jthi
Super User

Re: Concatenate all data tables using JSL

Which version of JMP are you using?

-Jarmo
jthi
Super User

Re: Concatenate all data tables using JSL

If JMP16+ I would use for each and loop over the list of tables

Names Default To Here(1);

dt1 = Open("$SAMPLE_DATA/Big Class.jmp");
dt2 = dt1 << Subset(All Rows, Selected Columns(0), Output Table("DEMO"));

dts = Get Data Table List();

dt_first = Remove From(dts, 1); // remove first table as we concatenate to that

For Each({dt}, dts,
	dt_first << Concatenate(
		dt,
		"Append to first table",
		"Create source column"
	);
	// Close(dt, no save);
);
-Jarmo

Re: Concatenate all data tables using JSL

Thank you for your response, however I'm struggling to make this apply to my situation (although I think it should be relatively easy).

What is dt? I get a name unresolved error.

I also don't have dt1 assigned as all the tables are already open from the previous part of the script. How can I assign it without directly calling a specific table?

 

If I do assign dt1 like below a demo table is produced however, the table is full of the word demo.

dt1 = Open( "$DOCUMENTS/Plot_Conduction_Losses/Module 6/DUT2/100C.jmp" );

 

Sorry if this is poorly explained and wordy.

jthi
Super User

Re: Concatenate all data tables using JSL

dt1 and dt2 are there just for demonstration purposes. You get the references to all open tables using Get Data Table List(). Which JMP version are you using (For each requires JMP16+, but it can be replaced with For)? dt is reference to a data table which can be found from the list of datatable referenes in dts.

-Jarmo

Re: Concatenate all data tables using JSL

I have JMP 17.

I understand the dt part now, sorry for the confusion.

Thank you for your help
jthi
Super User

Re: Concatenate all data tables using JSL

Didn't remember you can use a list with concatenate

Names Default To Here(1);

Open("$SAMPLE_DATA/Students.jmp");
Open("$SAMPLE_DATA/Students1.jmp");
Open("$SAMPLE_DATA/Students2.jmp");

dts = Get Data Table List();
dt_first = Remove From(dts, 1)[1]; // remove first table as we concatenate to that
dt_result = dt_first << Concatenate(dts, "Create source column");

Also have to/should get first index from Remove From() because Remove From() returns a lists.

-Jarmo