<?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: Compare Two Datasets and Remove Duplicates in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Compare-Two-Datasets-and-Remove-Duplicates/m-p/91198#M8461</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jen,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you please tell if there is any specific reason why you prefer to use PROC SQL?&lt;/P&gt;&lt;P&gt;The requirement can be achieved by DATA MERGE statements. Please see below two ways where the MASTER_NEW will have only IDs from T1 and not T2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1.&lt;/P&gt;&lt;P&gt;DATA MASTER_NEW;&lt;/P&gt;&lt;P&gt;MERGE MASTER (IN=T1) WEEKLY (IN=T2);&lt;/P&gt;&lt;P&gt;BY APPLICATION_ID;&lt;/P&gt;&lt;P&gt;IF T1 AND NOT T2 THEN OUTPUT;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2.&lt;/P&gt;&lt;P&gt;DATA MASTER_NEW;&lt;/P&gt;&lt;P&gt;MERGE MASTER (IN=T1) WEEKLY (IN=T2);&lt;/P&gt;&lt;P&gt;BY APPLICATION_ID;&lt;/P&gt;&lt;P&gt;IF T1 AND T2 THEN DELETE;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And the code piece below is one single step to arrive at your final result, to have MASTER dataset have the updates from WEEKLY without the need to merge them seperately after refining the MASTER dataset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This way:&lt;/P&gt;&lt;P&gt;DATA MASTER_NEW;&lt;/P&gt;&lt;P&gt;MERGE MASTER (IN=T1) WEEKLY (IN=T2);&lt;/P&gt;&lt;P&gt;BY APPLICATION_ID;&lt;/P&gt;&lt;P&gt;IF T1 AND T2 THEN PUT T2;&lt;/P&gt;&lt;P&gt;IF T1 AND NOT T2 THEN PUT T1;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;***But remember that to use DATA MERGE statements, your sas datasets need to be in sorted order by application_id field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; And I have given the code based on the assumption the MASTER and WEEKLY has the same layout and WEEKLY doesn't have new records not present in MASTER.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And if you still want to use PROC SQL, LEFT JOIN with COALESCE is what you need to look at. SAS Website has good description of LEFT JOIN with examples.&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473712.htm" title="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473712.htm"&gt;http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473712.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002206368.htm" title="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002206368.htm"&gt;http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002206368.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank You!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Aug 2012 13:24:49 GMT</pubDate>
    <dc:creator>HK_EndeavourForever</dc:creator>
    <dc:date>2012-08-12T13:24:49Z</dc:date>
    <item>
      <title>Compare Two Datasets and Remove Duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Compare-Two-Datasets-and-Remove-Duplicates/m-p/91197#M8460</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;Hello,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;I have two datasets:&amp;nbsp; Master dataset (with all weeks' data) and Weekly (current week's data).&amp;nbsp; The Weekly file could contain updates to IDs that are existing in the Master file.&amp;nbsp; I've tried to use UPDATE statement but had no luck with it.&amp;nbsp; So I am going to go about it a different way.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;I would like to compare the two files by a field name:&amp;nbsp; app_id.&amp;nbsp; If the same application id is in both datasets, then I would like remove them from the Master file.&amp;nbsp; Once I have a "modified" Master file, I then can merge the Master and Weekly files.&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt;"&gt;I know how to remove duplicates within the same dataset, but have never compared between two.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;What function or statement would I use to accomplish this.&amp;nbsp; Using an inner join will give me the IDs that are in both datasets, but would not delete the ID from the Master file. &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; CREATE TABLE MASTER_NEW AS &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; SELECT t1.APPLICATION_ID&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM MASTER t1 INNER JOIN WEEKLY t2 ON (t1.APPLICATION_ID&amp;nbsp; NOT = t2.APPLICATION_ID);&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The MASTER_NEW table should only have IDs from T1 that are not in T2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 16px;"&gt;Any advise is appreciated.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Aug 2012 02:26:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Compare-Two-Datasets-and-Remove-Duplicates/m-p/91197#M8460</guid>
      <dc:creator>jen123</dc:creator>
      <dc:date>2012-08-12T02:26:44Z</dc:date>
    </item>
    <item>
      <title>Re: Compare Two Datasets and Remove Duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Compare-Two-Datasets-and-Remove-Duplicates/m-p/91198#M8461</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jen,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you please tell if there is any specific reason why you prefer to use PROC SQL?&lt;/P&gt;&lt;P&gt;The requirement can be achieved by DATA MERGE statements. Please see below two ways where the MASTER_NEW will have only IDs from T1 and not T2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1.&lt;/P&gt;&lt;P&gt;DATA MASTER_NEW;&lt;/P&gt;&lt;P&gt;MERGE MASTER (IN=T1) WEEKLY (IN=T2);&lt;/P&gt;&lt;P&gt;BY APPLICATION_ID;&lt;/P&gt;&lt;P&gt;IF T1 AND NOT T2 THEN OUTPUT;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2.&lt;/P&gt;&lt;P&gt;DATA MASTER_NEW;&lt;/P&gt;&lt;P&gt;MERGE MASTER (IN=T1) WEEKLY (IN=T2);&lt;/P&gt;&lt;P&gt;BY APPLICATION_ID;&lt;/P&gt;&lt;P&gt;IF T1 AND T2 THEN DELETE;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And the code piece below is one single step to arrive at your final result, to have MASTER dataset have the updates from WEEKLY without the need to merge them seperately after refining the MASTER dataset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This way:&lt;/P&gt;&lt;P&gt;DATA MASTER_NEW;&lt;/P&gt;&lt;P&gt;MERGE MASTER (IN=T1) WEEKLY (IN=T2);&lt;/P&gt;&lt;P&gt;BY APPLICATION_ID;&lt;/P&gt;&lt;P&gt;IF T1 AND T2 THEN PUT T2;&lt;/P&gt;&lt;P&gt;IF T1 AND NOT T2 THEN PUT T1;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;***But remember that to use DATA MERGE statements, your sas datasets need to be in sorted order by application_id field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; And I have given the code based on the assumption the MASTER and WEEKLY has the same layout and WEEKLY doesn't have new records not present in MASTER.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And if you still want to use PROC SQL, LEFT JOIN with COALESCE is what you need to look at. SAS Website has good description of LEFT JOIN with examples.&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473712.htm" title="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473712.htm"&gt;http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473712.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002206368.htm" title="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002206368.htm"&gt;http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002206368.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank You!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Aug 2012 13:24:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Compare-Two-Datasets-and-Remove-Duplicates/m-p/91198#M8461</guid>
      <dc:creator>HK_EndeavourForever</dc:creator>
      <dc:date>2012-08-12T13:24:49Z</dc:date>
    </item>
    <item>
      <title>Re: Compare Two Datasets and Remove Duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Compare-Two-Datasets-and-Remove-Duplicates/m-p/91199#M8462</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for the response!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did try the MERGE statement and it didn't work.&amp;nbsp; That's because I had opposite of what you suggested - I had the table names after PUT reversed:&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;DATA MASTER_NEW;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;MERGE MASTER (IN=T1) WEEKLY (IN=T2);&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;BY APPLICATION_ID;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;IF T1 AND T2 THEN PUT &lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;T1&lt;/STRONG&gt;&lt;/SPAN&gt;;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;IF T1 AND NOT T2 THEN PUT &lt;STRONG style="text-decoration: underline;"&gt;T2&lt;/STRONG&gt;;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;RUN;&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;Thanks for the suggestion!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Aug 2012 13:34:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Compare-Two-Datasets-and-Remove-Duplicates/m-p/91199#M8462</guid>
      <dc:creator>jen123</dc:creator>
      <dc:date>2012-08-12T13:34:20Z</dc:date>
    </item>
    <item>
      <title>Re: Compare Two Datasets and Remove Duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Compare-Two-Datasets-and-Remove-Duplicates/m-p/91200#M8463</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I agree that a merge statement should work in this situation, but please be aware that the &lt;SPAN style="font-family: 'courier new', courier;"&gt;in=&lt;/SPAN&gt; data set option "Creates a &lt;SPAN style="text-decoration: underline;"&gt;variable&lt;/SPAN&gt; that indicates whether the data set contributed data to the current observation" - from the documentation. So in the &lt;SPAN style="font-family: 'courier new', courier;"&gt;merge&lt;/SPAN&gt; statement data set options, T1 and T2 are just &lt;SPAN style="text-decoration: underline;"&gt;variables&lt;/SPAN&gt;, they are not like the table alias names specified in the &lt;SPAN style="font-family: 'courier new', courier;"&gt;proc sql&lt;/SPAN&gt; code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Further the &lt;SPAN style="font-family: 'courier new', courier;"&gt;put&lt;/SPAN&gt; statement is &lt;EM&gt;not&lt;/EM&gt; used to output data to a SAS data set, for that in your code you should use the &lt;SPAN style="font-family: 'courier new', courier;"&gt;output&lt;/SPAN&gt; statement along with the data set name you want to output to, e.g.:&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;&lt;SPAN style="font-family: 'courier new', courier;"&gt;DATA MASTER_NEW &lt;STRONG&gt;/* WEEKLY_NEW */&lt;/STRONG&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; MERGE MASTER (IN=T1) WEEKLY (IN=T2);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; BY APPLICATION_ID;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&amp;nbsp; /*&lt;/STRONG&gt; IF T1 AND T2 THEN &lt;STRONG&gt;OUTPUT WEEKLY_NEW&lt;/STRONG&gt;; &lt;STRONG&gt;*/&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; IF T1 AND NOT T2 THEN &lt;STRONG&gt;OUTPUT MASTER_NEW&lt;/STRONG&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;RUN;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was not sure if you wanted a WEEKLY_NEW data set, if you do then you can just remove the comment markers "&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;/*&lt;/STRONG&gt;&lt;/SPAN&gt;" and "&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;*/&lt;/STRONG&gt;&lt;/SPAN&gt;".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hth.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Amir Malik - minor correction.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2012 10:57:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Compare-Two-Datasets-and-Remove-Duplicates/m-p/91200#M8463</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2012-08-13T10:57:31Z</dc:date>
    </item>
  </channel>
</rss>

