<?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 check if data exist in another table in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/check-if-data-exist-in-another-table/m-p/366915#M61672</link>
    <description>&lt;P&gt;Hi, I have 2 tables A and B, each has a column "email" and "id". I want to add a new column in table A, if that row has "the same email OR same id" showing up in table B, then "YES", if no then empty. Could someone help me how to write this script?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
    <pubDate>Fri, 09 Jun 2023 22:08:09 GMT</pubDate>
    <dc:creator>joann</dc:creator>
    <dc:date>2023-06-09T22:08:09Z</dc:date>
    <item>
      <title>check if data exist in another table</title>
      <link>https://community.jmp.com/t5/Discussions/check-if-data-exist-in-another-table/m-p/366915#M61672</link>
      <description>&lt;P&gt;Hi, I have 2 tables A and B, each has a column "email" and "id". I want to add a new column in table A, if that row has "the same email OR same id" showing up in table B, then "YES", if no then empty. Could someone help me how to write this script?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 22:08:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/check-if-data-exist-in-another-table/m-p/366915#M61672</guid>
      <dc:creator>joann</dc:creator>
      <dc:date>2023-06-09T22:08:09Z</dc:date>
    </item>
    <item>
      <title>Re: check if data exist in another table</title>
      <link>https://community.jmp.com/t5/Discussions/check-if-data-exist-in-another-table/m-p/366961#M61676</link>
      <description>&lt;P&gt;I am not sure what you are looking to do.&lt;/P&gt;
&lt;P&gt;Suppose this is Table A:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Dan_Obermiller_0-1615416598529.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/31154i1EFF4BC4549A1FE0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Dan_Obermiller_0-1615416598529.png" alt="Dan_Obermiller_0-1615416598529.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;and this is Table B:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Dan_Obermiller_1-1615416622559.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/31155i8CA37F72F30A57AA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Dan_Obermiller_1-1615416622559.png" alt="Dan_Obermiller_1-1615416622559.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;So, consider user1 in row 1 of both tables. There are two different id's. Which one should be kept? Or should we see that person listed twice? Similarly, what happens with id=84? Should there be two lines or should it have the user7 email address?&lt;/P&gt;</description>
      <pubDate>Wed, 10 Mar 2021 22:53:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/check-if-data-exist-in-another-table/m-p/366961#M61676</guid>
      <dc:creator>Dan_Obermiller</dc:creator>
      <dc:date>2021-03-10T22:53:02Z</dc:date>
    </item>
    <item>
      <title>Re: check if data exist in another table</title>
      <link>https://community.jmp.com/t5/Discussions/check-if-data-exist-in-another-table/m-p/366980#M61688</link>
      <description>&lt;P&gt;Hi, if I interpret your question correctly, you want a YES in table A whenever the e-mail or ID appears in B, regardless of the location in which these appear in table B. If so, this will do:&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);
dtA = datatable("tableA");
dtb = datatable("tableB");

//make lists of IDs and emails in table B
bIDs = dtB:ID &amp;lt;&amp;lt; get values;
bEmails = dtB:email &amp;lt;&amp;lt; get values;

//use formula to check if anything in the given row of A occurs anywhere in B
dtA &amp;lt;&amp;lt; new column("bMatch", character, formula(if(contains(bIDs, :ID) | contains(bEmails, :email), "YES", "")));
dtA:bMatch &amp;lt;&amp;lt; Delete Formula;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here is sample output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="brady_brady_0-1615428671490.png" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/31157i9A52BF0F2CB5BB30/image-size/large?v=v2&amp;amp;px=999" role="button" title="brady_brady_0-1615428671490.png" alt="brady_brady_0-1615428671490.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Brady&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 02:11:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/check-if-data-exist-in-another-table/m-p/366980#M61688</guid>
      <dc:creator>brady_brady</dc:creator>
      <dc:date>2021-03-11T02:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: check if data exist in another table</title>
      <link>https://community.jmp.com/t5/Discussions/check-if-data-exist-in-another-table/m-p/367168#M61710</link>
      <description>&lt;P&gt;Thank you! This is what I'm looking for.&lt;/P&gt;&lt;P&gt;I have one error with this script. Wonder if it's because there's an underscore within the col name?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2021-03-11 at 10.22.42 AM.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/31174iA6F6A2A26F883CA2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screen Shot 2021-03-11 at 10.22.42 AM.png" alt="Screen Shot 2021-03-11 at 10.22.42 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 15:24:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/check-if-data-exist-in-another-table/m-p/367168#M61710</guid>
      <dc:creator>joann</dc:creator>
      <dc:date>2021-03-11T15:24:49Z</dc:date>
    </item>
    <item>
      <title>Re: check if data exist in another table</title>
      <link>https://community.jmp.com/t5/Discussions/check-if-data-exist-in-another-table/m-p/367174#M61711</link>
      <description>&lt;P&gt;To my understanding _ shouldn't cause issues (at least not with JMP14.3 and JMP15.2). Are you sure you have&amp;nbsp; Email_HASHED column in your dtB datatable?&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 15:32:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/check-if-data-exist-in-another-table/m-p/367174#M61711</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-03-11T15:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: check if data exist in another table</title>
      <link>https://community.jmp.com/t5/Discussions/check-if-data-exist-in-another-table/m-p/367221#M61717</link>
      <description>Sorry my bad! Wrong column name, i fixed it and it worked! Thanks so much!&lt;BR /&gt;One following question- if in table b there's another column like country, which contains US or CA. Could I do the same YES column in table a but only when table b country = US?</description>
      <pubDate>Thu, 11 Mar 2021 16:38:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/check-if-data-exist-in-another-table/m-p/367221#M61717</guid>
      <dc:creator>joann</dc:creator>
      <dc:date>2021-03-11T16:38:30Z</dc:date>
    </item>
    <item>
      <title>Re: check if data exist in another table</title>
      <link>https://community.jmp.com/t5/Discussions/check-if-data-exist-in-another-table/m-p/367247#M61720</link>
      <description>&lt;P&gt;Yes, you can. I think the easiest way to do this is to restrict what you put in the lists in the first place, by filling the lists with only values that occurred in rows where country == US. See the new line below the first comment, as well as the [r] index used in the next 2 lines.&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 );
dtA = Data Table( "tableA" );
dtb = Data Table( "tableB" );

//make lists of IDs and emails in table B
r = dtB &amp;lt;&amp;lt; get rows where( :country == "US" );  //restrict rows to those where country is US
bIDs = (dtB:ID &amp;lt;&amp;lt; get values)[r];
bEmails = (dtB:email &amp;lt;&amp;lt; get values)[r];

//use formula to check if anything in the given row of A occurs anywhere in B
dtA &amp;lt;&amp;lt; New Column( "bMatch",
	character,
	formula( If( Contains( bIDs, :ID ) | Contains( bEmails, :email ), "YES", "" ) )
);
dtA:bMatch &amp;lt;&amp;lt; Delete Formula;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 17:39:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/check-if-data-exist-in-another-table/m-p/367247#M61720</guid>
      <dc:creator>brady_brady</dc:creator>
      <dc:date>2021-03-11T17:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: check if data exist in another table</title>
      <link>https://community.jmp.com/t5/Discussions/check-if-data-exist-in-another-table/m-p/367268#M61721</link>
      <description>It works! Thanks so much Brady!</description>
      <pubDate>Thu, 11 Mar 2021 18:35:47 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/check-if-data-exist-in-another-table/m-p/367268#M61721</guid>
      <dc:creator>joann</dc:creator>
      <dc:date>2021-03-11T18:35:47Z</dc:date>
    </item>
  </channel>
</rss>

