<?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 duplicate subject records by a variable in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/deleting-duplicate-subject-records-by-a-variable/m-p/532430#M16462</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp; &amp;nbsp;Thank you &lt;STRONG&gt;mr elegance &amp;amp; diligence&lt;/STRONG&gt; combined as always.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 03 Feb 2019 17:02:06 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-02-03T17:02:06Z</dc:date>
    <item>
      <title>deleting duplicate subject records by a variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/deleting-duplicate-subject-records-by-a-variable/m-p/531468#M16431</link>
      <description>&lt;P&gt;Hello everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I recently received data from the CDC's national death index. They provide death data for subjects and if duplicate records are found they provide back all of the data found and let you feed through it. There is one variable they return called exact match; however if there is an exact match and there are multiple records pulled up, they still send all the matching files. I would like to keep the exact match if found and delete any subsequent records for the same patient, without deleting duplicates for remaining records without exact matches. Below is an example of some data (not the real data of course). See patient ID #1 has an exact match, so I would want to keep that match and delete the following two. Patient ID #2 does not have an exact match, so I have to look at more information to see what row I want to keep, therefore I do not want to delete any records for patient ID #2.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp;DOB&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; State&amp;nbsp; &amp;nbsp;DeathDate&amp;nbsp; &amp;nbsp; &amp;nbsp; ExactMatch&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;9/15/2010&amp;nbsp; &amp;nbsp; &amp;nbsp; CO&amp;nbsp; &amp;nbsp; &amp;nbsp;10/26/2016&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;*&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;9/15/2010&amp;nbsp; &amp;nbsp; &amp;nbsp; IL&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10/28/2016&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;9/15/2010&amp;nbsp; &amp;nbsp; &amp;nbsp; MO&amp;nbsp; &amp;nbsp; &amp;nbsp;1/6/2016&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;10/2/2013&amp;nbsp; &amp;nbsp; &amp;nbsp; KY&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3/16/2016&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;10/2/2013&amp;nbsp; &amp;nbsp; &amp;nbsp; NY&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2/26/2016&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;10/2/2013&amp;nbsp; &amp;nbsp; &amp;nbsp; CO&amp;nbsp; &amp;nbsp; &amp;nbsp; 11/46/2016&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any help you can provide!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Stephanie&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 19:56:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/deleting-duplicate-subject-records-by-a-variable/m-p/531468#M16431</guid>
      <dc:creator>sjarvis847</dc:creator>
      <dc:date>2019-01-30T19:56:11Z</dc:date>
    </item>
    <item>
      <title>Re: deleting duplicate subject records by a variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/deleting-duplicate-subject-records-by-a-variable/m-p/531483#M16432</link>
      <description>&lt;P&gt;Assuming i understand your req&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input ID   DOB  :mmddyy10.            State  $ DeathDate   :mmddyy10.       ExactMatch $; 
format dob DeathDate mmddyy10.;
cards;
1     9/15/2010      CO     10/26/2016         *
1     9/15/2010      IL        10/28/2016
1     9/15/2010      MO     1/6/2016
2     10/2/2013      KY       3/16/2016           
2     10/2/2013      NY       2/26/2016          
2     10/2/2013      CO      11/26/2016
;

/*assuming your datasets are sorted by id as shown*/

data want;
merge have have(in=b where=(ExactMatch='*'));
by id;
if b then do;
if ExactMatch='*' then output;
end;
else output;
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Jan 2019 21:22:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/deleting-duplicate-subject-records-by-a-variable/m-p/531483#M16432</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-30T21:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: deleting duplicate subject records by a variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/deleting-duplicate-subject-records-by-a-variable/m-p/531488#M16433</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Assuming i understand your req&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;
infile cards truncover;
input ID   DOB  :mmddyy10.            State  $ DeathDate   :mmddyy10.       ExactMatch $; 
format dob DeathDate mmddyy10.;
cards;
1     9/15/2010      CO     10/26/2016         *
1     9/15/2010      IL        10/28/2016
1     9/15/2010      MO     1/6/2016
2     10/2/2013      KY       3/16/2016           
2     10/2/2013      NY       2/26/2016          
2     10/2/2013      CO      11/26/2016
;
/*sorting doesn't matter*/
data want;
if _n_=1 then do;
  declare hash H (dataset:'have(where=(ExactMatch="*"))') ;
   h.definekey  ('id') ;
   h.definedata ('id') ;
    h.definedone () ;
end;
set have;
rc= h.check();
if rc=0 then do;
if ExactMatch='*' then output;
end;
else output;
drop rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 21:40:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/deleting-duplicate-subject-records-by-a-variable/m-p/531488#M16433</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-30T21:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: deleting duplicate subject records by a variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/deleting-duplicate-subject-records-by-a-variable/m-p/532420#M16460</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;. &amp;nbsp; The merge of a sorted dataset with a specific subset of same is a very useful approach.&amp;nbsp; But don't overlook the additional power of a well-constructed subetting if statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider replacing&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if b then do;
if ExactMatch='*' then output;
end;
else output;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;with:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if b=0 or exactmatch='*';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Similarly for the hash offering for non-sorted data.&amp;nbsp; You can replace&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rc= h.check();
if rc=0 then do;
if ExactMatch='*' then output;
end;
else output;
drop rc;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;with&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if h.check()^=0 or exactmatch='*';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I knew study of set unions, intersections, and complements would be useful one day.&lt;/P&gt;</description>
      <pubDate>Sun, 03 Feb 2019 16:21:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/deleting-duplicate-subject-records-by-a-variable/m-p/532420#M16460</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-02-03T16:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: deleting duplicate subject records by a variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/deleting-duplicate-subject-records-by-a-variable/m-p/532430#M16462</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp; &amp;nbsp;Thank you &lt;STRONG&gt;mr elegance &amp;amp; diligence&lt;/STRONG&gt; combined as always.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Feb 2019 17:02:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/deleting-duplicate-subject-records-by-a-variable/m-p/532430#M16462</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-03T17:02:06Z</dc:date>
    </item>
  </channel>
</rss>

