<?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 Sort and delete ALL duplicated obs in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sort-and-delete-ALL-duplicated-obs/m-p/86796#M18534</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is there an easy one (PROC or DATA) step method of sorting and deleting ALL observations that have duplicate by variables INCLUDING the first occurrence of the duplicate? I can do this with the following code, but is there an elegant one step way of doing this? May be with PROC SQL? The following code removes four obs from the "dirty" data set (2 obs have duplicate BY variables hence 2*2=4), leaving only three obs in the final "cleaned" data set. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data dirty;&lt;/P&gt;&lt;P&gt;input var1 var2 x;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 1 4&lt;/P&gt;&lt;P&gt;1 2 5&lt;/P&gt;&lt;P&gt;1 3 6&lt;/P&gt;&lt;P&gt;1 1 5&lt;/P&gt;&lt;P&gt;2 2 5&lt;/P&gt;&lt;P&gt;2 4 6&lt;/P&gt;&lt;P&gt;2 2 1&lt;/P&gt;&lt;P&gt;; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=dirty out=cleaner dupout=dirt nodupkey; &lt;/P&gt;&lt;P&gt;&amp;nbsp; by var1 var2; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data cleaned; merge cleaner dirt (keep=var1 var2 in=del); &lt;/P&gt;&lt;P&gt;&amp;nbsp; by var1 var2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if del then delete; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Ian.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 24 Mar 2013 12:48:24 GMT</pubDate>
    <dc:creator>iank131</dc:creator>
    <dc:date>2013-03-24T12:48:24Z</dc:date>
    <item>
      <title>Sort and delete ALL duplicated obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-and-delete-ALL-duplicated-obs/m-p/86796#M18534</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is there an easy one (PROC or DATA) step method of sorting and deleting ALL observations that have duplicate by variables INCLUDING the first occurrence of the duplicate? I can do this with the following code, but is there an elegant one step way of doing this? May be with PROC SQL? The following code removes four obs from the "dirty" data set (2 obs have duplicate BY variables hence 2*2=4), leaving only three obs in the final "cleaned" data set. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data dirty;&lt;/P&gt;&lt;P&gt;input var1 var2 x;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 1 4&lt;/P&gt;&lt;P&gt;1 2 5&lt;/P&gt;&lt;P&gt;1 3 6&lt;/P&gt;&lt;P&gt;1 1 5&lt;/P&gt;&lt;P&gt;2 2 5&lt;/P&gt;&lt;P&gt;2 4 6&lt;/P&gt;&lt;P&gt;2 2 1&lt;/P&gt;&lt;P&gt;; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=dirty out=cleaner dupout=dirt nodupkey; &lt;/P&gt;&lt;P&gt;&amp;nbsp; by var1 var2; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data cleaned; merge cleaner dirt (keep=var1 var2 in=del); &lt;/P&gt;&lt;P&gt;&amp;nbsp; by var1 var2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if del then delete; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Ian.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 24 Mar 2013 12:48:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-and-delete-ALL-duplicated-obs/m-p/86796#M18534</guid>
      <dc:creator>iank131</dc:creator>
      <dc:date>2013-03-24T12:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: Sort and delete ALL duplicated obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-and-delete-ALL-duplicated-obs/m-p/86797#M18535</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A simpler non-sql solution :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt;"&gt;data dirty;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;input var1 var2 x;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;cards;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;1 1 4&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;1 2 5&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;1 3 6&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;1 1 5&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;2 2 5&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;2 4 6&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;2 2 1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt;"&gt;proc sort data=dirty; by var1 var2; run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt;"&gt;data clean;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;set dirty;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;by var1 var2;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;if first.var2 and last.var2;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 24 Mar 2013 13:22:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-and-delete-ALL-duplicated-obs/m-p/86797#M18535</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-03-24T13:22:00Z</dc:date>
    </item>
    <item>
      <title>Re: Sort and delete ALL duplicated obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-and-delete-ALL-duplicated-obs/m-p/86798#M18536</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And for a SQL solution :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt;"&gt;data dirty;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;input var1 var2 x;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;cards;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;1 1 4&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;1 2 5&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;1 3 6&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;1 1 5&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;2 2 5&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;2 4 6&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;2 2 1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt;"&gt;proc sql;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;create table clean as&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;select * from dirty&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;group by var1, var2&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;having count(*)=1;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt;"&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 24 Mar 2013 13:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-and-delete-ALL-duplicated-obs/m-p/86798#M18536</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-03-24T13:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: Sort and delete ALL duplicated obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-and-delete-ALL-duplicated-obs/m-p/86799#M18537</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks very much PG!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 24 Mar 2013 14:50:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-and-delete-ALL-duplicated-obs/m-p/86799#M18537</guid>
      <dc:creator>iank131</dc:creator>
      <dc:date>2013-03-24T14:50:39Z</dc:date>
    </item>
  </channel>
</rss>

