<?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: Joining complex tables in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Joining-complex-tables/m-p/466417#M71015</link>
    <description>&lt;P&gt;Jeff's answer is a great answer.&amp;nbsp; Here is my version, which uses the JSL created using similar steps that Jeff used, to create the new table&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="txnelson_0-1646255944836.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/40449iE883FD35FFA3AC4E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="txnelson_0-1646255944836.png" alt="txnelson_0-1646255944836.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);

dtData = New Table( "The Data",
	Add Rows( 5 ),
	New Column( "Patient ID",
		Character,
		"Nominal",
		Set Values(
			{"Patient A", "Patient A", "Patient B", "Patient B", "Patient B"}
		)
	),
	New Column( "Diagnosis",
		Character( 16 ),
		"Nominal",
		Set Values( {"Diabetes", "HTN", "Asthma", "HTN", "Sepsis"} )
	)
);
dtDemo = New Table( "The Demographics",
	Add Rows( 2 ),
	New Column( "Patient ID",
		Character,
		"Nominal",
		Set Values( {"Patient A", "Patient B"} )
	),
	New Column( "Age", Character( 16 ), "Nominal", Set Values( {"13", "15"} ) ),
	New Column( "Sex", Character( 16 ), "Nominal", Set Values( {"M", "F"} ) )
);

// Create a list with just the Patient IDs
summarize( dtData, theIDs = by( :Patient ID));
// Move it into a data table
dtIDs = New Table("theIDs", invisible, new column("Patient ID", character, values(theIDs)));

// Create a list with just the Diagnoses
summarize( dtData, theDiags = by( :Diagnosis));
// Move it into a data table
dtDiags = New Table("theDiags", invisible, new column("Diagnosis", character, values(theDiags)));

// Create a table with all possible combinations of patients and diagnoses
dtCart = dtIDs &amp;lt;&amp;lt; Join( With( dtDiags ), Cartesian Join );

// Cleanup
close( dtIDs, nosave );
close( dtDiags, nosave);

// Add a null diagnosis column
dtCart &amp;lt;&amp;lt; New Column("foundDiag", set each value(0));

dtData &amp;lt;&amp;lt; New Column("foundDiag", set each value(1));

// Put the tables together
dtCart &amp;lt;&amp;lt; Update(
	With( dtData),
	Match Columns( :Patient ID = :Patient ID, :Diagnosis = :Diagnosis )
);

// Split the data into the final form
dtSplit = dtCart &amp;lt;&amp;lt; Split(
	Split By( :Diagnosis ),
	Split( :foundDiag ),
	Group( :Patient ID ),
	Sort by Column Property
);

// Make a copy of the demographics data table
dtFinal = dtDemo &amp;lt;&amp;lt; subset( selected columns(0), selected rows(0));

// put the demographics file together with the split data table
dtFinal &amp;lt;&amp;lt; Update(
	With( dtSplit ),
	Match Columns( :Patient ID = :Patient ID )
);

// Cleanup
close( dtSplit, nosave );
close( dtCart, nosave );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 02 Mar 2022 21:19:34 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2022-03-02T21:19:34Z</dc:date>
    <item>
      <title>Joining complex tables</title>
      <link>https://community.jmp.com/t5/Discussions/Joining-complex-tables/m-p/466277#M71006</link>
      <description>&lt;P&gt;I'm trying to combine a couple of tables together and am having some problems. Basically my data sheets look like the following&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;Age&lt;/TD&gt;&lt;TD&gt;Sex&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Patient A&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;M&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Patient B&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;TD&gt;F&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Diagnosis&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Patient A&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;Diabetes&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Patient A&lt;/TD&gt;&lt;TD&gt;HTN&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Patient B&lt;/TD&gt;&lt;TD&gt;Asthma&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Patient B&lt;/TD&gt;&lt;TD&gt;HTN&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Patient B&lt;/TD&gt;&lt;TD&gt;Sepsis&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to make a table to combine the diagnoses with the patient codes (to look like the table below), but each patient diagnosis is represented individually in my current excel format rather than combining each patient with all their diagnoses. Is there an easy way to combine these two tables? Thanks!&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Age&lt;/TD&gt;&lt;TD&gt;Sex&lt;/TD&gt;&lt;TD&gt;Diabetes&lt;/TD&gt;&lt;TD&gt;HTN&lt;/TD&gt;&lt;TD&gt;Asthma&lt;/TD&gt;&lt;TD&gt;Sepsis&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Patient A&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;M&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Patient B&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;TD&gt;F&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:45:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Joining-complex-tables/m-p/466277#M71006</guid>
      <dc:creator>rariedl</dc:creator>
      <dc:date>2023-06-10T23:45:08Z</dc:date>
    </item>
    <item>
      <title>Re: Joining complex tables</title>
      <link>https://community.jmp.com/t5/Discussions/Joining-complex-tables/m-p/466364#M71010</link>
      <description>&lt;P&gt;This is pretty easy to do with a little manipulation using &lt;A href="https://www.jmp.com/support/help/en/16.2/#page/jmp/split-columns.shtml" target="_blank" rel="noopener"&gt;Tables-&amp;gt;Split&lt;/A&gt; on the Diagnosis table first. You just need to add a third column of 1s that you'll split.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2022-03-02_15-03-38.770.png" style="width: 849px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/40444i8B492C9F3CF6D55E/image-dimensions/849x225?v=v2" width="849" height="225" role="button" title="2022-03-02_15-03-38.770.png" alt="2022-03-02_15-03-38.770.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Then it's a matter of search and replace the missing values (.) with 0s and use &lt;A href="https://www.jmp.com/support/help/en/16.2/#page/jmp/join-data-tables.shtml#" target="_blank" rel="noopener"&gt;Tables-&amp;gt;Join&lt;/A&gt; by Patient.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2022-03-02_15-44-09.698.png" style="width: 748px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/40447i6C5E1D0CC6709DF8/image-dimensions/748x305?v=v2" width="748" height="305" role="button" title="2022-03-02_15-44-09.698.png" alt="2022-03-02_15-44-09.698.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 14:19:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Joining-complex-tables/m-p/466364#M71010</guid>
      <dc:creator>Jeff_Perkinson</dc:creator>
      <dc:date>2022-03-03T14:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: Joining complex tables</title>
      <link>https://community.jmp.com/t5/Discussions/Joining-complex-tables/m-p/466417#M71015</link>
      <description>&lt;P&gt;Jeff's answer is a great answer.&amp;nbsp; Here is my version, which uses the JSL created using similar steps that Jeff used, to create the new table&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="txnelson_0-1646255944836.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/40449iE883FD35FFA3AC4E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="txnelson_0-1646255944836.png" alt="txnelson_0-1646255944836.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);

dtData = New Table( "The Data",
	Add Rows( 5 ),
	New Column( "Patient ID",
		Character,
		"Nominal",
		Set Values(
			{"Patient A", "Patient A", "Patient B", "Patient B", "Patient B"}
		)
	),
	New Column( "Diagnosis",
		Character( 16 ),
		"Nominal",
		Set Values( {"Diabetes", "HTN", "Asthma", "HTN", "Sepsis"} )
	)
);
dtDemo = New Table( "The Demographics",
	Add Rows( 2 ),
	New Column( "Patient ID",
		Character,
		"Nominal",
		Set Values( {"Patient A", "Patient B"} )
	),
	New Column( "Age", Character( 16 ), "Nominal", Set Values( {"13", "15"} ) ),
	New Column( "Sex", Character( 16 ), "Nominal", Set Values( {"M", "F"} ) )
);

// Create a list with just the Patient IDs
summarize( dtData, theIDs = by( :Patient ID));
// Move it into a data table
dtIDs = New Table("theIDs", invisible, new column("Patient ID", character, values(theIDs)));

// Create a list with just the Diagnoses
summarize( dtData, theDiags = by( :Diagnosis));
// Move it into a data table
dtDiags = New Table("theDiags", invisible, new column("Diagnosis", character, values(theDiags)));

// Create a table with all possible combinations of patients and diagnoses
dtCart = dtIDs &amp;lt;&amp;lt; Join( With( dtDiags ), Cartesian Join );

// Cleanup
close( dtIDs, nosave );
close( dtDiags, nosave);

// Add a null diagnosis column
dtCart &amp;lt;&amp;lt; New Column("foundDiag", set each value(0));

dtData &amp;lt;&amp;lt; New Column("foundDiag", set each value(1));

// Put the tables together
dtCart &amp;lt;&amp;lt; Update(
	With( dtData),
	Match Columns( :Patient ID = :Patient ID, :Diagnosis = :Diagnosis )
);

// Split the data into the final form
dtSplit = dtCart &amp;lt;&amp;lt; Split(
	Split By( :Diagnosis ),
	Split( :foundDiag ),
	Group( :Patient ID ),
	Sort by Column Property
);

// Make a copy of the demographics data table
dtFinal = dtDemo &amp;lt;&amp;lt; subset( selected columns(0), selected rows(0));

// put the demographics file together with the split data table
dtFinal &amp;lt;&amp;lt; Update(
	With( dtSplit ),
	Match Columns( :Patient ID = :Patient ID )
);

// Cleanup
close( dtSplit, nosave );
close( dtCart, nosave );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 21:19:34 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Joining-complex-tables/m-p/466417#M71015</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2022-03-02T21:19:34Z</dc:date>
    </item>
  </channel>
</rss>

