<?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 check if a list contains any values from another list? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contains-any-values-from-another-list/m-p/829451#M101149</link>
    <description>&lt;P&gt;I usually use either For Each + Break or Associative Arrays but there are many different methods where you can use functions a bit "incorrectly" such as Transform Each ("one-liner" such as this are usually horrible ideas (in my opinion) as they tend to be difficult to read)&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 );

A = {1, 2, 3, 4, 5};
B = {3, 6, 7};

r = Eval(Transform Each({item}, A, Output("Expression", "Any"), Contains(B, item)));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It also depends on what you are comparing: strings, integers, floats, lists, ... as JMP lists can basically contain anything.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jan 2025 09:54:19 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2025-01-28T09:54:19Z</dc:date>
    <item>
      <title>How to check if a list contains any values from another list?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contains-any-values-from-another-list/m-p/829431#M101142</link>
      <description>&lt;P&gt;Is there an elegant one-liner for that rather than iterate through the second list using Contains() function?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2025 04:04:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contains-any-values-from-another-list/m-p/829431#M101142</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2025-01-28T04:04:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if a list contains any values from another list?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contains-any-values-from-another-list/m-p/829441#M101143</link>
      <description>&lt;P&gt;Not one-liner, but more elegant than a loop:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;A = {1, 2, 3, 4, 5};
B = {3, 6, 7};
check = Associative Array(A);
check &amp;lt;&amp;lt; Intersect(Associative Array(B));
N Items(check);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Jan 2025 04:26:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contains-any-values-from-another-list/m-p/829441#M101143</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2025-01-28T04:26:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if a list contains any values from another list?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contains-any-values-from-another-list/m-p/829442#M101144</link>
      <description>&lt;P&gt;You can loop through one of the lists and use Contains() to see if the specific list item is found anywhere in the other list.&lt;/P&gt;
&lt;P&gt;Or, you can convert both of the lists into separate Associative Arrays and then check for the Intersect between the two arrays.&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 );

listA = {"a", "b", "c"};

listB = {"d", "c", "f"};

inBothList = {};

For Each( {member}, listA,
	If( Contains( listB, member ),
		Insert Into( inBothList, member )
	)
);

Show( inBothList );

arrayA = Associative Array( listA );
arrayB = Associative Array( listB );

arrayA &amp;lt;&amp;lt; intersect( ArrayB);

show( arrayA );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Jan 2025 04:27:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contains-any-values-from-another-list/m-p/829442#M101144</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2025-01-28T04:27:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if a list contains any values from another list?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contains-any-values-from-another-list/m-p/829451#M101149</link>
      <description>&lt;P&gt;I usually use either For Each + Break or Associative Arrays but there are many different methods where you can use functions a bit "incorrectly" such as Transform Each ("one-liner" such as this are usually horrible ideas (in my opinion) as they tend to be difficult to read)&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 );

A = {1, 2, 3, 4, 5};
B = {3, 6, 7};

r = Eval(Transform Each({item}, A, Output("Expression", "Any"), Contains(B, item)));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It also depends on what you are comparing: strings, integers, floats, lists, ... as JMP lists can basically contain anything.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2025 09:54:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contains-any-values-from-another-list/m-p/829451#M101149</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-01-28T09:54:19Z</dc:date>
    </item>
  </channel>
</rss>

