<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Joining Multiple Tables by Row in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Joining-Multiple-Tables-by-Row/m-p/438942#M68760</link>
    <description>&lt;P&gt;Greetings,&lt;/P&gt;
&lt;P&gt;I’ve been beating my head for long enough with code that should be quite simple.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to take tables opened from multiple excel file and sheets and join them in a wide table with columns that are named to correspond to their excel sheet.&lt;/P&gt;
&lt;P&gt;In my case, columns should be as shown below.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P style="line-height: 1.71429;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="16.666666666666668%"&gt;Col 1 of TestWB1Sheet1&lt;/TD&gt;
&lt;TD width="16.666666666666668%"&gt;Col 2 of TestWB1Sheet1&lt;/TD&gt;
&lt;TD width="16.666666666666668%"&gt;Col 3 of TestWB1Sheet1&lt;/TD&gt;
&lt;TD width="16.666666666666668%"&gt;Col 1 of TestWB1Sheet2&lt;/TD&gt;
&lt;TD width="16.666666666666668%"&gt;...&lt;/TD&gt;
&lt;TD width="16.666666666666668%"&gt;Col 3 of TestWB2Sheet4&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P style="line-height: 1.71429;"&gt;The one catch is that I don't want to upload data from the last sheet in each excel file (sheet5 in my example).&lt;/P&gt;
&lt;P style="line-height: 1.71429;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I’ve tried using the code from this discussion but can’t seem to get the naming correct. &lt;A href="https://community.jmp.com/t5/Discussions/Joining-Multiple-Data-Table-using-a-loop/m-p/9451" target="_blank"&gt;https://community.jmp.com/t5/Discussions/Joining-Multiple-Data-Table-using-a-loop/m-p/9451&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;I believe the answer may be in this discussion but it is hard for me to digest the solution because of the extraneous code.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.jmp.com/t5/Discussions/Joining-multiple-DataTables-and-retaining-column-name/m-p/18874#M17198" target="_blank"&gt;https://community.jmp.com/t5/Discussions/Joining-multiple-DataTables-and-retaining-column-name/m-p/18874#M17198&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my simplified code that doesn’t name columns correctly:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default to Here(1);

//Close All is a convienience script to use while writing the script
//Close All(Data Tables, NoSave);

//Create list of files to open
file = Pick File("Pick file/files", "$Desktop", {"All Files|*"}, 1,0, "", multiple);

//create blank list of data tables
dtList = {};

//Open list of files to dtList 
for (i=1, i&amp;lt;=nitems(file), i++,
	
	ws = Get Excel Worksheets(file[i]);
	sws = ws[1::(N Items(ws) - 1)];
	
	show(i);
	
	for (s=1, s&amp;lt;=nitems(sws), s++,
		
		show(s);
	
		dt = Open(file[i], 
		Worksheets( sws[s] ), 
		use for all sheets( 1 ),
		Concatenate Worksheets( 0 ),
		Create Concatenation Column( 0 ),
		Worksheet Settings(
			1,
			Has Column Headers( 1 ),
			Number of Rows in Headers( 1 ),
			Headers Start on Row( 1 ),
			Data Starts on Row( 2 ),
			Data Starts on Column( 1 ),
			Data Ends on Row( 0 ),
			Data Ends on Column( 0 ),
			Replicated Spanned Rows( 1 ),
			Replicated Spanned Headers( 0 ),
			Suppress Hidden Rows( 1 ),
			Suppress Hidden Columns( 1 ),
			Suppress Empty Columns( 1 ),
			Treat as Hierarchy( 0 ),
			Multiple Series Stack( 0 ),
			Import Cell Colors( 0 ),
			Limit Column Detect( 0 ),
			Column Separator String( "-" )
			)
		);
		
	dt &amp;lt;&amp;lt; Set Name(char(i)||char(s));
		
	insert into (dtList, dt);
	)
);



//Designate dt_old to hold the joined data
dt_old = data table(dtList[1]);

//Join all tables in dtList to dt_old by row number
for ( i = 2, i &amp;lt;= N Items( dtList ), i++,
	
	dt_new = data table(dtList[i]);
	
	join_name = "Limits" || char(i);
	
	show(i);
	show(dt_new);
	
	dt_old &amp;lt;&amp;lt; Join( With (dt_new),
		By Row Number,
		Output Table( join_name )
	);
	
	show(dt_old);
	
	close(dt_old, nosave);
	
	dt_old = data table(join_name);
	
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks in advance for the help.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Jun 2023 18:05:54 GMT</pubDate>
    <dc:creator>danielrbiber</dc:creator>
    <dc:date>2023-06-09T18:05:54Z</dc:date>
    <item>
      <title>Joining Multiple Tables by Row</title>
      <link>https://community.jmp.com/t5/Discussions/Joining-Multiple-Tables-by-Row/m-p/438942#M68760</link>
      <description>&lt;P&gt;Greetings,&lt;/P&gt;
&lt;P&gt;I’ve been beating my head for long enough with code that should be quite simple.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to take tables opened from multiple excel file and sheets and join them in a wide table with columns that are named to correspond to their excel sheet.&lt;/P&gt;
&lt;P&gt;In my case, columns should be as shown below.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P style="line-height: 1.71429;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="16.666666666666668%"&gt;Col 1 of TestWB1Sheet1&lt;/TD&gt;
&lt;TD width="16.666666666666668%"&gt;Col 2 of TestWB1Sheet1&lt;/TD&gt;
&lt;TD width="16.666666666666668%"&gt;Col 3 of TestWB1Sheet1&lt;/TD&gt;
&lt;TD width="16.666666666666668%"&gt;Col 1 of TestWB1Sheet2&lt;/TD&gt;
&lt;TD width="16.666666666666668%"&gt;...&lt;/TD&gt;
&lt;TD width="16.666666666666668%"&gt;Col 3 of TestWB2Sheet4&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P style="line-height: 1.71429;"&gt;The one catch is that I don't want to upload data from the last sheet in each excel file (sheet5 in my example).&lt;/P&gt;
&lt;P style="line-height: 1.71429;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I’ve tried using the code from this discussion but can’t seem to get the naming correct. &lt;A href="https://community.jmp.com/t5/Discussions/Joining-Multiple-Data-Table-using-a-loop/m-p/9451" target="_blank"&gt;https://community.jmp.com/t5/Discussions/Joining-Multiple-Data-Table-using-a-loop/m-p/9451&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;I believe the answer may be in this discussion but it is hard for me to digest the solution because of the extraneous code.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.jmp.com/t5/Discussions/Joining-multiple-DataTables-and-retaining-column-name/m-p/18874#M17198" target="_blank"&gt;https://community.jmp.com/t5/Discussions/Joining-multiple-DataTables-and-retaining-column-name/m-p/18874#M17198&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my simplified code that doesn’t name columns correctly:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default to Here(1);

//Close All is a convienience script to use while writing the script
//Close All(Data Tables, NoSave);

//Create list of files to open
file = Pick File("Pick file/files", "$Desktop", {"All Files|*"}, 1,0, "", multiple);

//create blank list of data tables
dtList = {};

//Open list of files to dtList 
for (i=1, i&amp;lt;=nitems(file), i++,
	
	ws = Get Excel Worksheets(file[i]);
	sws = ws[1::(N Items(ws) - 1)];
	
	show(i);
	
	for (s=1, s&amp;lt;=nitems(sws), s++,
		
		show(s);
	
		dt = Open(file[i], 
		Worksheets( sws[s] ), 
		use for all sheets( 1 ),
		Concatenate Worksheets( 0 ),
		Create Concatenation Column( 0 ),
		Worksheet Settings(
			1,
			Has Column Headers( 1 ),
			Number of Rows in Headers( 1 ),
			Headers Start on Row( 1 ),
			Data Starts on Row( 2 ),
			Data Starts on Column( 1 ),
			Data Ends on Row( 0 ),
			Data Ends on Column( 0 ),
			Replicated Spanned Rows( 1 ),
			Replicated Spanned Headers( 0 ),
			Suppress Hidden Rows( 1 ),
			Suppress Hidden Columns( 1 ),
			Suppress Empty Columns( 1 ),
			Treat as Hierarchy( 0 ),
			Multiple Series Stack( 0 ),
			Import Cell Colors( 0 ),
			Limit Column Detect( 0 ),
			Column Separator String( "-" )
			)
		);
		
	dt &amp;lt;&amp;lt; Set Name(char(i)||char(s));
		
	insert into (dtList, dt);
	)
);



//Designate dt_old to hold the joined data
dt_old = data table(dtList[1]);

//Join all tables in dtList to dt_old by row number
for ( i = 2, i &amp;lt;= N Items( dtList ), i++,
	
	dt_new = data table(dtList[i]);
	
	join_name = "Limits" || char(i);
	
	show(i);
	show(dt_new);
	
	dt_old &amp;lt;&amp;lt; Join( With (dt_new),
		By Row Number,
		Output Table( join_name )
	);
	
	show(dt_old);
	
	close(dt_old, nosave);
	
	dt_old = data table(join_name);
	
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks in advance for the help.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 18:05:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Joining-Multiple-Tables-by-Row/m-p/438942#M68760</guid>
      <dc:creator>danielrbiber</dc:creator>
      <dc:date>2023-06-09T18:05:54Z</dc:date>
    </item>
    <item>
      <title>Re: Joining Multiple Tables by Row</title>
      <link>https://community.jmp.com/t5/Discussions/Joining-Multiple-Tables-by-Row/m-p/438971#M68762</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

//directory with files
xlsx_files = Files In Directory("./WB");

//dt collection list
dt_list = {};

For Each({file}, xlsx_files,
	//open datatables one by one
	dt = Open(
		"WB/" || file,
		Worksheets({"Sheet1", "Sheet2", "Sheet3", "Sheet4"}),
		Use for all sheets(1),
		Concatenate Worksheets(1),
		Create Concatenation Column(1),
		Worksheet Settings(
			1,
			Has Column Headers(1),
			Number of Rows in Headers(1),
			Headers Start on Row(1),
			Data Starts on Row(2),
			Data Starts on Column(1),
			Data Ends on Row(0),
			Data Ends on Column(0),
			Replicated Spanned Rows(1),
			Replicated Spanned Headers(0),
			Suppress Hidden Rows(1),
			Suppress Hidden Columns(1),
			Suppress Empty Columns(1),
			Treat as Hierarchy(0),
			Multiple Series Stack(0),
			Import Cell Colors(0),
			Limit Column Detect(0),
			Column Separator String("-")
		)
	);
	//add table name to SourceTable column
	Column(dt, "Source Table") &amp;lt;&amp;lt; Set Each Value(Word(1, file, ".") || :"Source Table");
	//add to dtlist
	Insert Into(dt_list, dt);
);

//concatenate
For(i = 2, i &amp;lt;= N Items(dt_list), i++,
	dt_list[1] &amp;lt;&amp;lt; Concatenate(dt_list[i], "Append to first table");
	Close(dt_list[i], no save);
);

//split
dt = dt_list[1] &amp;lt;&amp;lt; Split(
	Split By(:Source Table),
	Split(:Col1, :Col2, :Col3),
	Sort by Column Property
);
//Close(dt_list[1], no save);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;OL&gt;
&lt;LI&gt;Get all files in directory (should remove unnecessary files if there are any)&lt;/LI&gt;
&lt;LI&gt;Loop over the xlsx files while inserting them to list&lt;/LI&gt;
&lt;LI&gt;Concatenate all files to one jmp datatable&lt;/LI&gt;
&lt;LI&gt;Split the datatable&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Tables before concatenate:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1637604352728.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/37782i1B959F76AF7DA6AD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1637604352728.png" alt="jthi_0-1637604352728.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;After concatenate:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_1-1637604381613.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/37783i4C043110863DFAF7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_1-1637604381613.png" alt="jthi_1-1637604381613.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;After split:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_2-1637604404513.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/37784iEA1ABE2B88DDFEE5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_2-1637604404513.png" alt="jthi_2-1637604404513.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Nov 2021 18:07:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Joining-Multiple-Tables-by-Row/m-p/438971#M68762</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-11-22T18:07:39Z</dc:date>
    </item>
    <item>
      <title>Re: Joining Multiple Tables by Row</title>
      <link>https://community.jmp.com/t5/Discussions/Joining-Multiple-Tables-by-Row/m-p/438972#M68763</link>
      <description>&lt;P&gt;Here is my modification of your code to create all of the new columns, and to join them together&lt;/P&gt;
&lt;P&gt;I just had to add a simple piece of JSL to rename the columns.&amp;nbsp; All of the rest of your code worked fine.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

//Close All is a convienience script to use while writing the script
//Close All(Data Tables, NoSave);

//Create list of files to open
file = Pick File( "Pick file/files", "$Desktop", {"All Files|*"}, 1, 0, "", multiple );

//create blank list of data tables
dtList = {};

//Open list of files to dtList 
For( i = 1, i &amp;lt;= N Items( file ), i++, 
	
	ws = Get Excel Worksheets( file[i] );
	sws = ws[1 :: (N Items( ws ) - 1)];
	
	Show( i );
	
	For( s = 1, s &amp;lt;= N Items( sws ), s++, 
		
		Show( s );
	
		dt = Open(
			file[i],
			Worksheets( sws[s] ),
			use for all sheets( 1 ),
			Concatenate Worksheets( 0 ),
			Create Concatenation Column( 0 ),
			Worksheet Settings(
				1,
				Has Column Headers( 1 ),
				Number of Rows in Headers( 1 ),
				Headers Start on Row( 1 ),
				Data Starts on Row( 2 ),
				Data Starts on Column( 1 ),
				Data Ends on Row( 0 ),
				Data Ends on Column( 0 ),
				Replicated Spanned Rows( 1 ),
				Replicated Spanned Headers( 0 ),
				Suppress Hidden Rows( 1 ),
				Suppress Hidden Columns( 1 ),
				Suppress Empty Columns( 1 ),
				Treat as Hierarchy( 0 ),
				Multiple Series Stack( 0 ),
				Import Cell Colors( 0 ),
				Limit Column Detect( 0 ),
				Column Separator String( "-" )
			)
		);
		
		dt &amp;lt;&amp;lt; Set Name( Char( i ) || Char( s ) );
		
		Insert Into( dtList, dt );
	
	// set new column names
		currFileName = Word( -2, File[i], ".\/" );
		For( k = 1, k &amp;lt;= N Cols( dt ), k++,
			Column( dt, k ) &amp;lt;&amp;lt; set name(
				Column( dt, k ) &amp;lt;&amp;lt; get name || " of " || currFileName || sws[s]
			)
		);
	);
);

//Designate dt_old to hold the joined data
dt_old = Data Table( dtList[1] );

//Join all tables in dtList to dt_old by row number
For( i = 2, i &amp;lt;= N Items( dtList ), i++, 
	
	dt_new = Data Table( dtList[i] );
	
	join_name = "Limits" || Char( i );
	
	Show( i );
	Show( dt_new );
	
	dt_old &amp;lt;&amp;lt; Join( With( dt_new ), By Row Number, Output Table( join_name ) );
	
	Show( dt_old );
	
	Close( dt_old, nosave );
	
	dt_old = Data Table( join_name );
	
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Nov 2021 18:13:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Joining-Multiple-Tables-by-Row/m-p/438972#M68763</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-11-22T18:13:03Z</dc:date>
    </item>
  </channel>
</rss>

