<?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 Proc Sql inner join- avoid duplicates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-inner-join-avoid-duplicates/m-p/462073#M117565</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am struggling to join two table without creating duplicate rows using proc&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;sql&amp;nbsp;( not sure if any other method is more efficient).&lt;/P&gt;
&lt;P&gt;Inner join is on: datepart(table1.date)=datepart(table2.date) AND tag=tag AND ID=ID&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the problem is date and different names in table 1. By just looking that the table its clear that table1's row 1 should be joined with table 2's row 1 because the transaction&amp;nbsp;started at 00:04 in table one and finished at 00:06 in table 2. I issue I am having is I cant join on dates with the timestamp so I am removing timestamps and because of that its creating duplicates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table1:&lt;/P&gt;
&lt;P&gt;id tag&amp;nbsp; &amp;nbsp;&amp;nbsp;date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; amount&amp;nbsp; &amp;nbsp;name_x&lt;BR /&gt;1 23&amp;nbsp; &amp;nbsp; &amp;nbsp; 01JUL2018:00:04&amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; smith ltd&lt;BR /&gt;1 23&amp;nbsp; &amp;nbsp; &amp;nbsp; 01JUL2018:00:09&amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; anna smith&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;table 2:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;id tag&amp;nbsp; ref&amp;nbsp; &amp;nbsp;amount&amp;nbsp; &amp;nbsp;date&lt;BR /&gt;1 23&amp;nbsp; &amp;nbsp;19&amp;nbsp; &amp;nbsp;12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01JUL2018:00:06:00&lt;BR /&gt;1 23&amp;nbsp; &amp;nbsp;20&amp;nbsp; &amp;nbsp;12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01JUL2018:00:10:00&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Desired output:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;id tag&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp; &amp;nbsp;date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; amount&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;name_x&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ref&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 23&amp;nbsp; &amp;nbsp; &amp;nbsp; 01JUL2018&amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; smith ltd&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;19&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 23&amp;nbsp; &amp;nbsp; &amp;nbsp; 01JUL2018&amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; anna smith&amp;nbsp; &amp;nbsp;20&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Appreciate your help.&lt;/P&gt;</description>
    <pubDate>Mon, 14 May 2018 15:15:03 GMT</pubDate>
    <dc:creator>Anna_nag</dc:creator>
    <dc:date>2018-05-14T15:15:03Z</dc:date>
    <item>
      <title>Proc Sql inner join- avoid duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-inner-join-avoid-duplicates/m-p/462073#M117565</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am struggling to join two table without creating duplicate rows using proc&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;sql&amp;nbsp;( not sure if any other method is more efficient).&lt;/P&gt;
&lt;P&gt;Inner join is on: datepart(table1.date)=datepart(table2.date) AND tag=tag AND ID=ID&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the problem is date and different names in table 1. By just looking that the table its clear that table1's row 1 should be joined with table 2's row 1 because the transaction&amp;nbsp;started at 00:04 in table one and finished at 00:06 in table 2. I issue I am having is I cant join on dates with the timestamp so I am removing timestamps and because of that its creating duplicates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table1:&lt;/P&gt;
&lt;P&gt;id tag&amp;nbsp; &amp;nbsp;&amp;nbsp;date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; amount&amp;nbsp; &amp;nbsp;name_x&lt;BR /&gt;1 23&amp;nbsp; &amp;nbsp; &amp;nbsp; 01JUL2018:00:04&amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; smith ltd&lt;BR /&gt;1 23&amp;nbsp; &amp;nbsp; &amp;nbsp; 01JUL2018:00:09&amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; anna smith&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;table 2:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;id tag&amp;nbsp; ref&amp;nbsp; &amp;nbsp;amount&amp;nbsp; &amp;nbsp;date&lt;BR /&gt;1 23&amp;nbsp; &amp;nbsp;19&amp;nbsp; &amp;nbsp;12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01JUL2018:00:06:00&lt;BR /&gt;1 23&amp;nbsp; &amp;nbsp;20&amp;nbsp; &amp;nbsp;12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01JUL2018:00:10:00&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Desired output:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;id tag&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp; &amp;nbsp;date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; amount&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;name_x&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ref&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 23&amp;nbsp; &amp;nbsp; &amp;nbsp; 01JUL2018&amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; smith ltd&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;19&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 23&amp;nbsp; &amp;nbsp; &amp;nbsp; 01JUL2018&amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; anna smith&amp;nbsp; &amp;nbsp;20&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Appreciate your help.&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 15:15:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-inner-join-avoid-duplicates/m-p/462073#M117565</guid>
      <dc:creator>Anna_nag</dc:creator>
      <dc:date>2018-05-14T15:15:03Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql inner join- avoid duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-inner-join-avoid-duplicates/m-p/462082#M117568</link>
      <description>&lt;P&gt;So what is the rule then to join?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;You will get duplicates so how do you know which ones to keep and which ones not to keep?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;In a simple example like this you could use a MERGE without a BY statement but I suspect that won't generalize to your actual data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 15:20:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-inner-join-avoid-duplicates/m-p/462082#M117568</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-05-14T15:20:32Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql inner join- avoid duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-inner-join-avoid-duplicates/m-p/462085#M117571</link>
      <description>&lt;P&gt;Timestamp is the rule..&amp;nbsp;table 1 row1 transaction always occurs before table 2 row1 and should be joined but I am struggling on how to do that.&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 15:34:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-inner-join-avoid-duplicates/m-p/462085#M117571</guid>
      <dc:creator>Anna_nag</dc:creator>
      <dc:date>2018-05-14T15:34:33Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql inner join- avoid duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-inner-join-avoid-duplicates/m-p/462088#M117574</link>
      <description>&lt;P&gt;Or another way to phrase it, the&amp;nbsp;datetime in table 2 is the smallest time that is greater than the datetime in table1? Will this hold for other cases? Can you provide several more data points and expected output to ensure the logic is correct?&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 15:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-inner-join-avoid-duplicates/m-p/462088#M117574</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-05-14T15:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql inner join- avoid duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-inner-join-avoid-duplicates/m-p/462090#M117575</link>
      <description>&lt;P&gt;Yes that will hold the logic. Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 15:27:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-inner-join-avoid-duplicates/m-p/462090#M117575</guid>
      <dc:creator>Anna_nag</dc:creator>
      <dc:date>2018-05-14T15:27:47Z</dc:date>
    </item>
  </channel>
</rss>

