<?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: Append unique records from one table to another in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Append-unique-records-from-one-table-to-another/m-p/212668#M52521</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Heh. That's a neat use of the first.ID!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 11 May 2015 09:01:30 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2015-05-11T09:01:30Z</dc:date>
    <item>
      <title>Append unique records from one table to another</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Append-unique-records-from-one-table-to-another/m-p/212664#M52517</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am new to SAS and have had no training, so please be specific in your response.&lt;/P&gt;&lt;P&gt;I have 2 tables, HRIS &amp;amp; TERM.&amp;nbsp; Both have the same 138 fields, and key fields of ID.&lt;/P&gt;&lt;P&gt;Some of the records in the TERM table have the same ID as records in the HRIS table.&lt;/P&gt;&lt;P&gt;A&lt;SPAN style="font-size: 11.0pt; font-family: 'Arial','sans-serif';"&gt;I want to add all records from the TERM table to the HRIS, but only if the ID in the TERM table is not in the HRIS table.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 10 May 2015 16:21:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Append-unique-records-from-one-table-to-another/m-p/212664#M52517</guid>
      <dc:creator>sasbanker</dc:creator>
      <dc:date>2015-05-10T16:21:00Z</dc:date>
    </item>
    <item>
      <title>Re: Append unique records from one table to another</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Append-unique-records-from-one-table-to-another/m-p/212665#M52518</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Probably a MERGE is the easiest way to do this, assuming your data is already sorted by ID and the ID key is unique in both tables. By using the IN = option you can identify which records are coming from which table. The IF statement will keep all records read from HRIS plus any records from TERM that are not in HRIS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data HRIS;&lt;/P&gt;&lt;P&gt;&amp;nbsp; merge HRIS (in = HR)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TERM (in = TM)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by ID;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if HR or (not HR and TM); &amp;lt;=== This is the same as saying: if HR = 1 or (HR = 0 and TM = 1)&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 May 2015 02:35:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Append-unique-records-from-one-table-to-another/m-p/212665#M52518</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2015-05-11T02:35:16Z</dc:date>
    </item>
    <item>
      <title>Re: Append unique records from one table to another</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Append-unique-records-from-one-table-to-another/m-p/212666#M52519</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The problem with that approoach are the shared columns. In case where an ID is present in both tables, TERM values may overwrite HRIS values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My quick solution:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table HRIS_new as&lt;/P&gt;&lt;P&gt;select * from HRIS&lt;/P&gt;&lt;P&gt;union all&lt;/P&gt;&lt;P&gt;select b.* from TEMP b left join HRIS c on b.ID = c.ID&lt;/P&gt;&lt;P&gt;where c.ID is missing&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 May 2015 06:01:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Append-unique-records-from-one-table-to-another/m-p/212666#M52519</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-05-11T06:01:45Z</dc:date>
    </item>
    <item>
      <title>Re: Append unique records from one table to another</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Append-unique-records-from-one-table-to-another/m-p/212667#M52520</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Of course Kurt you are quite correct. This variation should work though assuming ID is unique in both datasets:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data HRIS;&lt;/P&gt;&lt;P&gt; set HRIS (in = HR)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TERM (in = TM)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by ID;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (HR and first.ID) or (TM and first.ID);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 May 2015 08:53:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Append-unique-records-from-one-table-to-another/m-p/212667#M52520</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2015-05-11T08:53:14Z</dc:date>
    </item>
    <item>
      <title>Re: Append unique records from one table to another</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Append-unique-records-from-one-table-to-another/m-p/212668#M52521</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Heh. That's a neat use of the first.ID!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 May 2015 09:01:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Append-unique-records-from-one-table-to-another/m-p/212668#M52521</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-05-11T09:01:30Z</dc:date>
    </item>
    <item>
      <title>Re: Append unique records from one table to another</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Append-unique-records-from-one-table-to-another/m-p/212669#M52522</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks.&amp;nbsp; Muchly appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 May 2015 12:21:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Append-unique-records-from-one-table-to-another/m-p/212669#M52522</guid>
      <dc:creator>sasbanker</dc:creator>
      <dc:date>2015-05-11T12:21:27Z</dc:date>
    </item>
    <item>
      <title>Re: Append unique records from one table to another</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Append-unique-records-from-one-table-to-another/m-p/212670#M52523</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would use Hash Table if the table is big.&lt;/P&gt;&lt;P&gt;Code not tested.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc sql;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;create table HRIS_new as&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;select * from HRIS&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;union all&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;select b.* from TEMP b where b.id in&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;(&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;select id from TEMP&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;except&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;select id from HRIS&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;) &lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 May 2015 12:31:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Append-unique-records-from-one-table-to-another/m-p/212670#M52523</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2015-05-11T12:31:52Z</dc:date>
    </item>
  </channel>
</rss>

