<?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: How to stack several columns into a new column ignoring duplicate entries? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-stack-several-columns-into-a-new-column-ignoring/m-p/677313#M86361</link>
    <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;Thanks. But does this drop duplicates?&lt;/P&gt;&lt;P&gt;My Columns (to be stacked) have common Char entries between them but also unique entries. I want to keep each in the new column dropping the duplicates.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Sep 2023 13:07:44 GMT</pubDate>
    <dc:creator>Neo</dc:creator>
    <dc:date>2023-09-13T13:07:44Z</dc:date>
    <item>
      <title>How to stack several columns into a new column ignoring duplicate entries?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-stack-several-columns-into-a-new-column-ignoring/m-p/677276#M86357</link>
      <description>&lt;P&gt;I have multi column (character, nominal) data table. I want to get the the entries/items in the last four columns into a new column in the same data table ignoring duplicate entries/items from the columns being stacked. How to achieve this in JSL?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2023 11:47:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-stack-several-columns-into-a-new-column-ignoring/m-p/677276#M86357</guid>
      <dc:creator>Neo</dc:creator>
      <dc:date>2023-09-13T11:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to stack several columns into a new column ignoring duplicate entries?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-stack-several-columns-into-a-new-column-ignoring/m-p/677292#M86359</link>
      <description>&lt;P&gt;Without knowing how your data looks and and how it should look like in the end my best guess is to use combination of &lt;EM&gt;Associative Array() &amp;lt;&amp;lt; Get Keys&lt;/EM&gt; and &lt;EM&gt;Concat Items()&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2023 12:22:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-stack-several-columns-into-a-new-column-ignoring/m-p/677292#M86359</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-09-13T12:22:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to stack several columns into a new column ignoring duplicate entries?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-stack-several-columns-into-a-new-column-ignoring/m-p/677313#M86361</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;Thanks. But does this drop duplicates?&lt;/P&gt;&lt;P&gt;My Columns (to be stacked) have common Char entries between them but also unique entries. I want to keep each in the new column dropping the duplicates.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2023 13:07:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-stack-several-columns-into-a-new-column-ignoring/m-p/677313#M86361</guid>
      <dc:creator>Neo</dc:creator>
      <dc:date>2023-09-13T13:07:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to stack several columns into a new column ignoring duplicate entries?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-stack-several-columns-into-a-new-column-ignoring/m-p/677326#M86362</link>
      <description>&lt;P&gt;&lt;A href="https://www.jmp.com/support/help/en/17.1/index.shtml#page/jmp/associative-arrays-in-jsl-scripts.shtml" target="_blank" rel="noopener"&gt;Associative Arrays&lt;/A&gt; cannot have duplicated keys, so yes it will (it is also ordered so order might change).&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2023 13:06:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-stack-several-columns-into-a-new-column-ignoring/m-p/677326#M86362</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-09-13T13:06:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to stack several columns into a new column ignoring duplicate entries?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-stack-several-columns-into-a-new-column-ignoring/m-p/677346#M86365</link>
      <description>&lt;P&gt;Here are some ways to do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Table Operations:
&lt;UL&gt;
&lt;LI&gt;Stack the columns in to one column using Tables &amp;gt; Stack&lt;/LI&gt;
&lt;LI&gt;Use Tables &amp;gt; Summary with that stacked column as the Group role&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;JSL
&lt;UL&gt;
&lt;LI&gt;Get column values into a list
&lt;UL&gt;
&lt;LI&gt;list_of_values = column(table name, column name) &amp;lt;&amp;lt; get values&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;You can do this again on another column and insert those values into the list
&lt;UL&gt;
&lt;LI&gt;list_of_values = Insert Into(list_of_values, column(table name, another column name) &amp;lt;&amp;lt; get values)&lt;/LI&gt;
&lt;LI&gt;repeat as necessary&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;Use an Associate Array to get the unique values
&lt;UL&gt;
&lt;LI&gt;unique_values = (Associative Array(list_of_values)) &amp;lt;&amp;lt; get keys&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;put that list of values into a new column in a &amp;nbsp;data table&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;Names Default To Here( 1 );

// create table with 4 columns with random letters
nr = 20;
dt = New Table( "Example", addrows( nr ) );

letterlist = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q",
"R", "S", "T", "U", "V", "W", "X", "Y", "Z"};

dt &amp;lt;&amp;lt; New Column( "C1", character );
Column( dt, "C1" ) &amp;lt;&amp;lt; set values( letterlist[J( nr, 1, Random Integer( 26 ) )] );
dt &amp;lt;&amp;lt; New Column( "C2", character );
Column( dt, "C2" ) &amp;lt;&amp;lt; set values( letterlist[J( nr, 1, Random Integer( 26 ) )] );
dt &amp;lt;&amp;lt; New Column( "C3", character );
Column( dt, "C3" ) &amp;lt;&amp;lt; set values( letterlist[J( nr, 1, Random Integer( 26 ) )] );
dt &amp;lt;&amp;lt; New Column( "C4", character );
Column( dt, "C4" ) &amp;lt;&amp;lt; set values( letterlist[J( nr, 1, Random Integer( 26 ) )] );

// Method 1
dtstack = dt &amp;lt;&amp;lt; Stack(
	columns( :C1, :C2, :C3, :C4 ),
	Source Label Column( "Label" ),
	Stacked Data Column( "Data" ),
	Output Table( "Stacked Values" )
);

dtstack &amp;lt;&amp;lt; Summary(
	Group( :Data ),
	Freq( "None" ),
	Weight( "None" ),
	output table name( "Unique Values" )
);

//Method 2
list_of_values = Column( dt, "C1" ) &amp;lt;&amp;lt; get values;
Insert Into( list_of_values, Column( dt, "C2" ) &amp;lt;&amp;lt; get values );
Insert Into( list_of_values, Column( dt, "C3" ) &amp;lt;&amp;lt; get values );
Insert Into( list_of_values, Column( dt, "C4" ) &amp;lt;&amp;lt; get values );
Print( list_of_values );
unique_values = (Associative Array( list_of_values )) &amp;lt;&amp;lt; get keys;

dtunique = New Table( "Unique Values" );
dtunique &amp;lt;&amp;lt; New Column( "Unique Values", character );
Column( dtunique, "Unique Values" ) &amp;lt;&amp;lt; set values( unique_values );
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2023 13:29:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-stack-several-columns-into-a-new-column-ignoring/m-p/677346#M86365</guid>
      <dc:creator>SamGardner</dc:creator>
      <dc:date>2023-09-13T13:29:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to stack several columns into a new column ignoring duplicate entries?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-stack-several-columns-into-a-new-column-ignoring/m-p/677347#M86366</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;OK. Thanks. Is this the correct syntax?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;aa = Associative Array( As Column(lastCH), As Column(2ndLastCH), As Column(3rdLastCH), As Column(4rthLastCH)) &amp;lt;&amp;lt; get keys();
// Where "lastCH", "2ndlastCH", "3rdlastCH" and "4rthlastCH" are column headers for the last four columns in my data table, supplied from above &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Sep 2023 13:33:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-stack-several-columns-into-a-new-column-ignoring/m-p/677347#M86366</guid>
      <dc:creator>Neo</dc:creator>
      <dc:date>2023-09-13T13:33:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to stack several columns into a new column ignoring duplicate entries?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-stack-several-columns-into-a-new-column-ignoring/m-p/677372#M86368</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/32729"&gt;@SamGardner&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both these work fine, but appends an empty row if the number of rows is not the same for every column as in the case of my actual data set.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2023 14:02:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-stack-several-columns-into-a-new-column-ignoring/m-p/677372#M86368</guid>
      <dc:creator>Neo</dc:creator>
      <dc:date>2023-09-13T14:02:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to stack several columns into a new column ignoring duplicate entries?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-stack-several-columns-into-a-new-column-ignoring/m-p/677481#M86381</link>
      <description>&lt;P&gt;if you insert the code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;remove from(unique_values, loc(unique_values,"")[1])
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;after the line where the unique_values list is created, that will remove the value from the list that is the empty string.&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;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;remove from(unique_values, 1)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;should also work, since the keys are sorted alphabetically with they are requested. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2023 19:11:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-stack-several-columns-into-a-new-column-ignoring/m-p/677481#M86381</guid>
      <dc:creator>SamGardner</dc:creator>
      <dc:date>2023-09-13T19:11:53Z</dc:date>
    </item>
  </channel>
</rss>

