<?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: Convert array into string in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Convert-array-into-string/m-p/401686#M65261</link>
    <description>&lt;P&gt;Craige,&lt;/P&gt;
&lt;P&gt;Once again I learned something new about JMP.&amp;nbsp; I had originally written the code using a Contains() function, but then converted to using the Loc() function, because what I thought would be an issue where&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Contains( "BARBARA ANN", "BARBARA")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;returns a True.&lt;/P&gt;
&lt;P&gt;I had (wrongly it turns out) that if the compare component of the Contains is a JMP List of items,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Contains( {"BARBARA ANN", "BETTY", "DAVID"}, "BARBARA")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;would also return a True, however, it returns a False, which means it does an absolute match.&lt;/P&gt;
&lt;P&gt;Thanks for the great info&lt;/P&gt;</description>
    <pubDate>Fri, 16 Jul 2021 12:44:22 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2021-07-16T12:44:22Z</dc:date>
    <item>
      <title>Convert array into string</title>
      <link>https://community.jmp.com/t5/Discussions/Convert-array-into-string/m-p/401572#M65250</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to get a value from an array from another table and use it as value for my selection. Is there a way to get convert the array into a string?&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;name_key = associative array(column(ref_file_1, "NAME") &amp;lt;&amp;lt; get values) &amp;lt;&amp;lt; get keys;
merged_file &amp;lt;&amp;lt; select where(:Name_final==name_key);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:33:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Convert-array-into-string/m-p/401572#M65250</guid>
      <dc:creator>29755</dc:creator>
      <dc:date>2023-06-10T23:33:59Z</dc:date>
    </item>
    <item>
      <title>Re: Convert array into string</title>
      <link>https://community.jmp.com/t5/Discussions/Convert-array-into-string/m-p/401583#M65251</link>
      <description>&lt;P&gt;I think this will give you what you want&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;name_key = associative array(column(ref_file_1, "NAME") &amp;lt;&amp;lt; get values) &amp;lt;&amp;lt; get keys;
merged_file &amp;lt;&amp;lt; select where(nrows(loc(name_key,:Name_final))&amp;gt;0);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Jul 2021 03:29:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Convert-array-into-string/m-p/401583#M65251</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-07-16T03:29:07Z</dc:date>
    </item>
    <item>
      <title>Re: Convert array into string</title>
      <link>https://community.jmp.com/t5/Discussions/Convert-array-into-string/m-p/401658#M65259</link>
      <description>&lt;P&gt;Again, amazed at Jim's ability to get to the heart of the question. Two nice bits of code here deserve a longer explanation:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What does this do?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;name_key = associative array(column(ref_file_1, "NAME") &amp;lt;&amp;lt; get values) &amp;lt;&amp;lt; get keys;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;EM&gt;ref_file_1&lt;/EM&gt; is a data table reference, &lt;EM&gt;"NAME"&lt;/EM&gt; is a column's name as a string (literally, "NAME", but could be in a variable), and the &lt;EM&gt;column&lt;/EM&gt; function returns a column reference. The &lt;EM&gt;&amp;lt;&amp;lt;get values&lt;/EM&gt; message gets all the values from the column, including duplicates. The &lt;EM&gt;associative array&lt;/EM&gt; function creates a set of the unique values, and the &lt;EM&gt;&amp;lt;&amp;lt;get keys&lt;/EM&gt; message returns the unique values. (Nicely done &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/29755"&gt;@29755&lt;/a&gt;.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and this?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;merged_file &amp;lt;&amp;lt; select where(nrows(loc(name_key,:Name_final))&amp;gt;0);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The &lt;EM&gt;&amp;lt;&amp;lt;select where&lt;/EM&gt; message operates on each row of the &lt;EM&gt;merged_file&lt;/EM&gt;, one at a time and selects rows when the argument is non-zero.&lt;/P&gt;&lt;P&gt;The &lt;EM&gt;loc()&lt;/EM&gt; function returns a matrix of indexes. It searches the list in &lt;EM&gt;name_key&lt;/EM&gt; for occurrences of :Name_final. The resulting matrix can have zero or more rows, though in this example it will have 0 or 1 row because the keys are unique. The &lt;EM&gt;nrows()&lt;/EM&gt; function returns 0 or 1 which is then compared &amp;gt;0 and remains 0 or 1. So rows are selected if :Name_final is in the list of ref_file_1:NAME.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alternative:&lt;/P&gt;&lt;P&gt;What if there were &amp;gt;1e6 names in name_key and &amp;gt;1e7 rows in merge_file? What would the performance look like? The loc function will be searching, a lot. It will compare 1e13 strings. You'll get tired of waiting. The fix for that is to use the associative array like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;nameSet = associative array(column(ref_file_1, "NAME") &amp;lt;&amp;lt; get values);
merged_file &amp;lt;&amp;lt; select where(contains(nameSet, :Name_final));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Now there are only 1e7 lookups in nameSet. They are not free, but they are much faster than checking 1e6 items sequentially. I'll guess about 20 compares each (log2(1e6)). This may also be easier for the next maintainer to follow.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(Untested. Corrections welcome!)&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 10:42:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Convert-array-into-string/m-p/401658#M65259</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-07-16T10:42:19Z</dc:date>
    </item>
    <item>
      <title>Re: Convert array into string</title>
      <link>https://community.jmp.com/t5/Discussions/Convert-array-into-string/m-p/401686#M65261</link>
      <description>&lt;P&gt;Craige,&lt;/P&gt;
&lt;P&gt;Once again I learned something new about JMP.&amp;nbsp; I had originally written the code using a Contains() function, but then converted to using the Loc() function, because what I thought would be an issue where&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Contains( "BARBARA ANN", "BARBARA")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;returns a True.&lt;/P&gt;
&lt;P&gt;I had (wrongly it turns out) that if the compare component of the Contains is a JMP List of items,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Contains( {"BARBARA ANN", "BETTY", "DAVID"}, "BARBARA")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;would also return a True, however, it returns a False, which means it does an absolute match.&lt;/P&gt;
&lt;P&gt;Thanks for the great info&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 12:44:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Convert-array-into-string/m-p/401686#M65261</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-07-16T12:44:22Z</dc:date>
    </item>
  </channel>
</rss>

