<?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: Remove duplicates with higher values within a variable in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Remove-duplicates-with-higher-values-within-a-variable/m-p/630633#M18893</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/206535"&gt;@kp19&lt;/a&gt;&amp;nbsp; Do you mean this?&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 have
group by id
having TimeDifference=min(TimeDifference);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could keep it simple by sorting the dataset by id timedifference, and picking the first obs within a by group i.e.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by id timedifference;
run;

data want;
 set have;
 by id;
 if first.id;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 09 Mar 2020 13:54:32 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-03-09T13:54:32Z</dc:date>
    <item>
      <title>Remove duplicates with higher values within a variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Remove-duplicates-with-higher-values-within-a-variable/m-p/630625#M18890</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to remove duplicates within same by group which have higher value of time difference variable.&lt;/P&gt;&lt;P&gt;The current data:&lt;/P&gt;&lt;P&gt;Obs ID&amp;nbsp; &amp;nbsp; date1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;time1&amp;nbsp; &amp;nbsp;date2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;time2&amp;nbsp; &amp;nbsp; &amp;nbsp;TimeDifference&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 03/08/20&amp;nbsp; &amp;nbsp; &amp;nbsp;11:00&amp;nbsp; &amp;nbsp;03/08/20&amp;nbsp; &amp;nbsp;10:55&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 03/08/20&amp;nbsp; &amp;nbsp; &amp;nbsp;11:00&amp;nbsp; &amp;nbsp;03/08/20&amp;nbsp; &amp;nbsp;10:15&amp;nbsp; &amp;nbsp; &amp;nbsp;45&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 03/08/20&amp;nbsp; &amp;nbsp; &amp;nbsp;11:00&amp;nbsp; &amp;nbsp;03/08/20&amp;nbsp; &amp;nbsp;9:30&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;90&lt;/P&gt;&lt;P&gt;i want to delete last two observations. I want to do this for multiple IDs with multiple such rows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Mar 2020 13:31:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Remove-duplicates-with-higher-values-within-a-variable/m-p/630625#M18890</guid>
      <dc:creator>kp19</dc:creator>
      <dc:date>2020-03-09T13:31:05Z</dc:date>
    </item>
    <item>
      <title>Re: Remove duplicates with higher values within a variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Remove-duplicates-with-higher-values-within-a-variable/m-p/630627#M18891</link>
      <description>&lt;P&gt;What if two obs have timedif=5?&lt;/P&gt;</description>
      <pubDate>Mon, 09 Mar 2020 13:32:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Remove-duplicates-with-higher-values-within-a-variable/m-p/630627#M18891</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-03-09T13:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: Remove duplicates with higher values within a variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Remove-duplicates-with-higher-values-within-a-variable/m-p/630629#M18892</link>
      <description>&lt;P&gt;They don't have same TimeDiff.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Mar 2020 13:33:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Remove-duplicates-with-higher-values-within-a-variable/m-p/630629#M18892</guid>
      <dc:creator>kp19</dc:creator>
      <dc:date>2020-03-09T13:33:22Z</dc:date>
    </item>
    <item>
      <title>Re: Remove duplicates with higher values within a variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Remove-duplicates-with-higher-values-within-a-variable/m-p/630633#M18893</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/206535"&gt;@kp19&lt;/a&gt;&amp;nbsp; Do you mean this?&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 have
group by id
having TimeDifference=min(TimeDifference);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could keep it simple by sorting the dataset by id timedifference, and picking the first obs within a by group i.e.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by id timedifference;
run;

data want;
 set have;
 by id;
 if first.id;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Mar 2020 13:54:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Remove-duplicates-with-higher-values-within-a-variable/m-p/630633#M18893</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-09T13:54:32Z</dc:date>
    </item>
    <item>
      <title>Re: Remove duplicates with higher values within a variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Remove-duplicates-with-higher-values-within-a-variable/m-p/630634#M18894</link>
      <description>&lt;P&gt;Here is one way. I added another ID for demonstration&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID date1 :mmddyy8. time1 :time5. date2 :mmddyy8. time2 :time5. TimeDifference;
format date: mmddyy8. time1 time2 time5.;
datalines;
1 03/08/20 11:00 03/08/20 10:55 5 
1 03/08/20 11:00 03/08/20 10:15 45
1 03/08/20 11:00 03/08/20 9:30  90
2 03/08/20 11:00 03/08/20 10:55 5 
2 03/08/20 11:00 03/08/20 10:15 45
2 03/08/20 11:00 03/08/20 9:30  90
;

data want (drop=minTD);
    minTD = 1e9;
    do _N_=1 by 1 until (last.ID);
        set have;
        by ID;
        if TimeDifference &amp;lt; minTD then minTD = TimeDifference;
    end;
    do _N_=1 to _N_;
        set have;
        if minTD = TimeDifference then output;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Mar 2020 13:46:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Remove-duplicates-with-higher-values-within-a-variable/m-p/630634#M18894</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-03-09T13:46:34Z</dc:date>
    </item>
    <item>
      <title>Re: Remove duplicates with higher values within a variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Remove-duplicates-with-higher-values-within-a-variable/m-p/630644#M18895</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt; This works well. Thanks a lot&lt;/P&gt;</description>
      <pubDate>Mon, 09 Mar 2020 14:24:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Remove-duplicates-with-higher-values-within-a-variable/m-p/630644#M18895</guid>
      <dc:creator>kp19</dc:creator>
      <dc:date>2020-03-09T14:24:56Z</dc:date>
    </item>
    <item>
      <title>Re: Remove duplicates with higher values within a variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Remove-duplicates-with-higher-values-within-a-variable/m-p/630645#M18896</link>
      <description>&lt;P&gt;Anytime &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Mar 2020 14:27:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Remove-duplicates-with-higher-values-within-a-variable/m-p/630645#M18896</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-03-09T14:27:08Z</dc:date>
    </item>
  </channel>
</rss>

