<?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: Deleting duplicates based on multiple criteria in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Deleting-duplicates-based-on-multiple-criteria/m-p/369002#M88023</link>
    <description>&lt;P&gt;I hope the dataset has the same variables liek person, score1,score2 and year. if that is the case then replace the dataset name with your dataset, like replace have in the below code with your dataset name. this will create the dataset want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as select * from (select *, count(*) as count, 
case when count(*)&amp;gt;1 and score1=score2 then 1
when count(*)&amp;gt;1 and score1^=score2 then 2 else count(*) end as flag from have 
group by person,year ) group by person having min(year)=year and min(flag)=flag;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 21 Jun 2017 03:15:46 GMT</pubDate>
    <dc:creator>Jagadishkatam</dc:creator>
    <dc:date>2017-06-21T03:15:46Z</dc:date>
    <item>
      <title>Deleting duplicates based on multiple criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-duplicates-based-on-multiple-criteria/m-p/368989#M88014</link>
      <description>&lt;P&gt;I want to delete and keep observations based on multiple conditions. For example, in the following dataset I want to do the following:&lt;/P&gt;&lt;P&gt;If there is duplicates of a person i want to keep the one where score1=score2. If this still leave duplicates of that person then I want the person with the lower year (i.e 2015 not 2016). If there are duplicates for a person but score1 is not equal to score2 for any of them then I want to keep the one with the lower year. I have illustrated how i want the original data set to look below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE cellspacing="0" cellpadding="0" border="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt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gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Person&lt;/TD&gt;&lt;TD&gt;Score1&lt;/TD&gt;&lt;TD&gt;Score2&lt;/TD&gt;&lt;TD&gt;Year&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;TD&gt;2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;2016&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;2015&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that if there is no duplicates for a person then I want to keep them regardless of whether score1=score2.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2017 01:41:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-duplicates-based-on-multiple-criteria/m-p/368989#M88014</guid>
      <dc:creator>BenBrady</dc:creator>
      <dc:date>2017-06-21T01:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting duplicates based on multiple criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-duplicates-based-on-multiple-criteria/m-p/368996#M88019</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Pease try the sql&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Person$ Score1	Score2	Year;
cards;
A	15	15	2015
A	15	15	2016
A	15	12	2016
B	8	7	2015
C	10	10	2016
D	11	12	2015
D	11	13	2016
;

proc sql;&lt;BR /&gt;create table want as select * from (select *, count(*) as count, &lt;BR /&gt;case when count(*)&amp;gt;1 and score1=score2 then 1&lt;BR /&gt;when count(*)&amp;gt;1 and score1^=score2 then 2 else count(*) end as flag from have &lt;BR /&gt;group by person,year ) group by person having min(year)=year and min(flag)=flag;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Jun 2017 03:13:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-duplicates-based-on-multiple-criteria/m-p/368996#M88019</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2017-06-21T03:13:36Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting duplicates based on multiple criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-duplicates-based-on-multiple-criteria/m-p/368999#M88022</link>
      <description>&lt;BR /&gt;&lt;BR /&gt;Thanks! How would I change the SAS code to make it applicable to an exisiting data set with the same variables that have thousands of observations?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 21 Jun 2017 02:54:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-duplicates-based-on-multiple-criteria/m-p/368999#M88022</guid>
      <dc:creator>BenBrady</dc:creator>
      <dc:date>2017-06-21T02:54:38Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting duplicates based on multiple criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-duplicates-based-on-multiple-criteria/m-p/369002#M88023</link>
      <description>&lt;P&gt;I hope the dataset has the same variables liek person, score1,score2 and year. if that is the case then replace the dataset name with your dataset, like replace have in the below code with your dataset name. this will create the dataset want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as select * from (select *, count(*) as count, 
case when count(*)&amp;gt;1 and score1=score2 then 1
when count(*)&amp;gt;1 and score1^=score2 then 2 else count(*) end as flag from have 
group by person,year ) group by person having min(year)=year and min(flag)=flag;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Jun 2017 03:15:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-duplicates-based-on-multiple-criteria/m-p/369002#M88023</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2017-06-21T03:15:46Z</dc:date>
    </item>
  </channel>
</rss>

