<?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 Re: Concatenate data tables by matching column names. in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Concatenate-data-tables-by-matching-column-names/m-p/210601#M42159</link>
    <description>&lt;P&gt;(If there is a better way, someone post it!)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are doing this through JMP's menus, make subsets with the common columns and concatenate the subsets. To automate that with JSL, something like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt1 = New Table( "Untitled 6", invisible,
	New Column( "a", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2] ) ),
	New Column( "b", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [3, 4] ) ),
	New Column( "c", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [5, 6] ) ),
	New Column( "d", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [7, 8] ) )
);
dt2 = New Table( "Untitled 7", invisible,
	New Column( "b", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [9, 10] ) ),
	New Column( "c", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [11, 12] ) ),
	New Column( "d", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [13, 14] ) ),
	New Column( "e", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [15, 16] ) )
);
// find column names common to both tables
names1 = dt1 &amp;lt;&amp;lt; getcolumnnames( "string" ); // {"a", "b", "c", "d"}
names2 = dt2 &amp;lt;&amp;lt; getcolumnnames( "string" ); // {"b", "c", "d", "e"}
// associative arrays offer a nice intersection method
set1 = Associative Array( names1 ); // ["a" =&amp;gt; 1, "b" =&amp;gt; 1, "c" =&amp;gt; 1, "d" =&amp;gt; 1, =&amp;gt; 0]
set2 = Associative Array( names2 ); // ["b" =&amp;gt; 1, "c" =&amp;gt; 1, "d" =&amp;gt; 1, "e" =&amp;gt; 1, =&amp;gt; 0]
common = set1; // make a copy; &amp;lt;&amp;lt;intersect updates the left-hand-side
common &amp;lt;&amp;lt; intersect( set2 ); // common==["b" =&amp;gt; 1, "c" =&amp;gt; 1, "d" =&amp;gt; 1, =&amp;gt; 0]
commonnames = common &amp;lt;&amp;lt; getkeys; // {"b", "c", "d"}
// make subsets by selecting columns
dt1s = dt1 &amp;lt;&amp;lt; Subset( All rows, columns( commonnames ), linked );
dt2s = dt2 &amp;lt;&amp;lt; Subset( All rows, columns( commonnames ), linked );
// do the concatenation; tweak the extra parameters as needed
dt = dt1s &amp;lt;&amp;lt; Concatenate( dt2s, Output Table( "ConcatTable" ), Create source column );
// clean up the intermediate tables
close(dt1s,nosave);
close(dt2s,nosave);
close(dt1,nosave);
close(dt2,nosave);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Concatenated common columns" style="width: 830px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/17428i7FF2ED631BFE6A13/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Concatenated common columns" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Concatenated common columns&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Update: add the &lt;EM&gt;linked&lt;/EM&gt; keyword to the &amp;lt;&amp;lt;subset for efficiency.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 24 May 2019 22:50:50 GMT</pubDate>
    <dc:creator>Craige_Hales</dc:creator>
    <dc:date>2019-05-24T22:50:50Z</dc:date>
    <item>
      <title>Concatenate data tables by matching column names.</title>
      <link>https://community.jmp.com/t5/Discussions/Concatenate-data-tables-by-matching-column-names/m-p/210568#M42156</link>
      <description>&lt;P&gt;Have two data tables.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;DT1&amp;nbsp; has Colm: A, B, C, E, H, I.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;DT2 has colm: A, B ,C , D ,E ,F, G, H, I&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I need to concatenate Dt2 rows to DT1's rows but only the columns that match to DT1. So dont want colms: D, F, G, from DT2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for the help.&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2019 20:40:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Concatenate-data-tables-by-matching-column-names/m-p/210568#M42156</guid>
      <dc:creator>Faisal_MEM</dc:creator>
      <dc:date>2019-05-24T20:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate data tables by matching column names.</title>
      <link>https://community.jmp.com/t5/Discussions/Concatenate-data-tables-by-matching-column-names/m-p/210601#M42159</link>
      <description>&lt;P&gt;(If there is a better way, someone post it!)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are doing this through JMP's menus, make subsets with the common columns and concatenate the subsets. To automate that with JSL, something like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt1 = New Table( "Untitled 6", invisible,
	New Column( "a", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2] ) ),
	New Column( "b", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [3, 4] ) ),
	New Column( "c", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [5, 6] ) ),
	New Column( "d", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [7, 8] ) )
);
dt2 = New Table( "Untitled 7", invisible,
	New Column( "b", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [9, 10] ) ),
	New Column( "c", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [11, 12] ) ),
	New Column( "d", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [13, 14] ) ),
	New Column( "e", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [15, 16] ) )
);
// find column names common to both tables
names1 = dt1 &amp;lt;&amp;lt; getcolumnnames( "string" ); // {"a", "b", "c", "d"}
names2 = dt2 &amp;lt;&amp;lt; getcolumnnames( "string" ); // {"b", "c", "d", "e"}
// associative arrays offer a nice intersection method
set1 = Associative Array( names1 ); // ["a" =&amp;gt; 1, "b" =&amp;gt; 1, "c" =&amp;gt; 1, "d" =&amp;gt; 1, =&amp;gt; 0]
set2 = Associative Array( names2 ); // ["b" =&amp;gt; 1, "c" =&amp;gt; 1, "d" =&amp;gt; 1, "e" =&amp;gt; 1, =&amp;gt; 0]
common = set1; // make a copy; &amp;lt;&amp;lt;intersect updates the left-hand-side
common &amp;lt;&amp;lt; intersect( set2 ); // common==["b" =&amp;gt; 1, "c" =&amp;gt; 1, "d" =&amp;gt; 1, =&amp;gt; 0]
commonnames = common &amp;lt;&amp;lt; getkeys; // {"b", "c", "d"}
// make subsets by selecting columns
dt1s = dt1 &amp;lt;&amp;lt; Subset( All rows, columns( commonnames ), linked );
dt2s = dt2 &amp;lt;&amp;lt; Subset( All rows, columns( commonnames ), linked );
// do the concatenation; tweak the extra parameters as needed
dt = dt1s &amp;lt;&amp;lt; Concatenate( dt2s, Output Table( "ConcatTable" ), Create source column );
// clean up the intermediate tables
close(dt1s,nosave);
close(dt2s,nosave);
close(dt1,nosave);
close(dt2,nosave);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Concatenated common columns" style="width: 830px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/17428i7FF2ED631BFE6A13/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Concatenated common columns" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Concatenated common columns&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Update: add the &lt;EM&gt;linked&lt;/EM&gt; keyword to the &amp;lt;&amp;lt;subset for efficiency.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2019 22:50:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Concatenate-data-tables-by-matching-column-names/m-p/210601#M42159</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2019-05-24T22:50:50Z</dc:date>
    </item>
  </channel>
</rss>

