<?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: Sorting a table, de-duping three variables and keeping the first occurrence of a fourth in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sorting-a-table-de-duping-three-variables-and-keeping-the-first/m-p/717531#M221919</link>
    <description>&lt;P&gt;Thank you very much, it does indeed work! I think I need to do a little more reading on FIRST and LAST then, as I don't quite understand it yet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you again&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 08 Feb 2021 10:01:35 GMT</pubDate>
    <dc:creator>uahmed97</dc:creator>
    <dc:date>2021-02-08T10:01:35Z</dc:date>
    <item>
      <title>Sorting a table, de-duping three variables and keeping the first occurrence of a fourth</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-a-table-de-duping-three-variables-and-keeping-the-first/m-p/717516#M221909</link>
      <description>&lt;P&gt;This is my first post, so apologies if this question is not worded/formatted correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to sort a dataset that has the following rough structure:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;First Name&lt;/TD&gt;&lt;TD&gt;Last Name&lt;/TD&gt;&lt;TD&gt;Date of Birth&lt;/TD&gt;&lt;TD&gt;Unique ID&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;John&lt;/TD&gt;&lt;TD&gt;Smith&lt;/TD&gt;&lt;TD&gt;01/01/1970&lt;/TD&gt;&lt;TD&gt;1000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;John&lt;/TD&gt;&lt;TD&gt;Smith&lt;/TD&gt;&lt;TD&gt;01/01/1970&lt;/TD&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Jane&lt;/TD&gt;&lt;TD&gt;Smith&lt;/TD&gt;&lt;TD&gt;01/03/1975&lt;/TD&gt;&lt;TD&gt;3000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Jane&lt;/TD&gt;&lt;TD&gt;Smith&lt;/TD&gt;&lt;TD&gt;06/08/1980&lt;/TD&gt;&lt;TD&gt;4000&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The rough operation I want to carry out is to de-duplicate the first name, last name and dob (with all three representing a single person), and then keep the biggest number for unique ID.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want to achieve is this:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;First Name&lt;/TD&gt;&lt;TD&gt;Last Name&lt;/TD&gt;&lt;TD&gt;Date of Birth&lt;/TD&gt;&lt;TD&gt;Unique ID&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;John&lt;/TD&gt;&lt;TD&gt;Smith&lt;/TD&gt;&lt;TD&gt;01/01/1970&lt;/TD&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Jane&lt;/TD&gt;&lt;TD&gt;Smith&lt;/TD&gt;&lt;TD&gt;01/03/1975&lt;/TD&gt;&lt;TD&gt;3000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Jane&lt;/TD&gt;&lt;TD&gt;Smith&lt;/TD&gt;&lt;TD&gt;06/08/1980&lt;/TD&gt;&lt;TD&gt;4000&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My initial thought was to try something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA people_sorted;
    SET people;
PROC SORT DATA=people_sorted;
    BY id;
RUN;
PROC SORT DATA=people_sorted NODUPKEY;
    BY fname lname dob;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This does not retain the original sorting as I had initially thought.&lt;/P&gt;&lt;P&gt;I was wondering if there was a way to 'chain' these sorts together, so to speak. Alternatively, is there a better approach to this that I'm not seeing?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for your help!&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 09:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-a-table-de-duping-three-variables-and-keeping-the-first/m-p/717516#M221909</guid>
      <dc:creator>uahmed97</dc:creator>
      <dc:date>2021-02-08T09:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting a table, de-duping three variables and keeping the first occurrence of a fourth</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-a-table-de-duping-three-variables-and-keeping-the-first/m-p/717519#M221910</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input FirstName $ LastName $ DateofBirth :ddmmyy10. UniqueID;
format DateofBirth :ddmmyy10.;
datalines;
John Smith 01/01/1970 1000
John Smith 01/01/1970 2000
Jane Smith 01/03/1975 3000
Jane Smith 06/08/1980 4000
;

proc sort data = have;
   by FirstName LastName DateofBirth UniqueID;
run;

data want;
   set have;
   by FirstName LastName DateofBirth UniqueID;
   if last.DateofBirth;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Feb 2021 09:26:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-a-table-de-duping-three-variables-and-keeping-the-first/m-p/717519#M221910</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-08T09:26:32Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting a table, de-duping three variables and keeping the first occurrence of a fourth</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-a-table-de-duping-three-variables-and-keeping-the-first/m-p/717522#M221912</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Forgive me if I misunderstand, but would this not ignore if two people happen to have the same date of birth?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, if the data was:&lt;/P&gt;&lt;P&gt;John Smith 01/01/1970 1000&lt;/P&gt;&lt;P&gt;Jane Doe 01/01/1970 2000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your solution would keep only Jane Doe, instead of keeping both people?&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 09:37:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-a-table-de-duping-three-variables-and-keeping-the-first/m-p/717522#M221912</guid>
      <dc:creator>uahmed97</dc:creator>
      <dc:date>2021-02-08T09:37:26Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting a table, de-duping three variables and keeping the first occurrence of a fourth</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-a-table-de-duping-three-variables-and-keeping-the-first/m-p/717527#M221917</link>
      <description>&lt;P&gt;No &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&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;
input FirstName $ LastName $ DateofBirth :ddmmyy10. UniqueID;
format DateofBirth :ddmmyy10.;
datalines;
John Smith 01/01/1970 1000
Jane Smith 01/01/1970 2000
;

proc sort data = have;
   by FirstName LastName DateofBirth UniqueID;
run;

data want;
   set have;
   by FirstName LastName DateofBirth UniqueID;
   if last.DateofBirth;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;FirstName LastName DateofBirth UniqueID 
Jane      Smith    01/01/1970  2000 
John      Smith    01/01/1970  1000 &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 09:48:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-a-table-de-duping-three-variables-and-keeping-the-first/m-p/717527#M221917</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-08T09:48:36Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting a table, de-duping three variables and keeping the first occurrence of a fourth</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-a-table-de-duping-three-variables-and-keeping-the-first/m-p/717531#M221919</link>
      <description>&lt;P&gt;Thank you very much, it does indeed work! I think I need to do a little more reading on FIRST and LAST then, as I don't quite understand it yet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you again&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 10:01:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-a-table-de-duping-three-variables-and-keeping-the-first/m-p/717531#M221919</guid>
      <dc:creator>uahmed97</dc:creator>
      <dc:date>2021-02-08T10:01:35Z</dc:date>
    </item>
  </channel>
</rss>

