<?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: Retrieve a record with max time when both records are same in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Retrieve-a-record-with-max-time-when-both-records-are-same/m-p/238399#M43807</link>
    <description>&lt;P&gt;The concept is correct, use a sort and BY group processing. Sort such that for duplicate records the latest time is at the top and then take the first record for each group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=output;
by datea amount descending time;
run;

data want;
set output;
by datea amount;
if first.amount;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 08 Dec 2015 22:38:21 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2015-12-08T22:38:21Z</dc:date>
    <item>
      <title>Retrieve a record with max time when both records are same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retrieve-a-record-with-max-time-when-both-records-are-same/m-p/238380#M43795</link>
      <description>&lt;P&gt;datea&amp;nbsp;&amp;nbsp;&amp;nbsp; time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; customer&lt;BR /&gt;2015-11-20&amp;nbsp; 11:18:36.0000000&amp;nbsp;&amp;nbsp;lucy&lt;BR /&gt;2015-11-20&amp;nbsp; 11:21:09.0000000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lucy&lt;/P&gt;
&lt;P&gt;dateb&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; amount&lt;BR /&gt;2015-11-20&amp;nbsp; 250&lt;/P&gt;
&lt;P&gt;output&lt;/P&gt;
&lt;P&gt;datea&amp;nbsp;&amp;nbsp;&amp;nbsp; time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; customer&amp;nbsp; amount&lt;BR /&gt;2015-11-20&amp;nbsp; 11:18:36.0000000&amp;nbsp;&amp;nbsp;lucy&amp;nbsp;&amp;nbsp; 250&lt;BR /&gt;2015-11-20&amp;nbsp; 11:21:09.0000000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lucy&amp;nbsp;&amp;nbsp; 250&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have three tables and i have an output where it has two records but the amounts are duplicated so how to pick a record with max time . can anyone pls help&lt;/P&gt;</description>
      <pubDate>Tue, 08 Dec 2015 20:58:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retrieve-a-record-with-max-time-when-both-records-are-same/m-p/238380#M43795</guid>
      <dc:creator>chennupriya</dc:creator>
      <dc:date>2015-12-08T20:58:28Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve a record with max time when both records are same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retrieve-a-record-with-max-time-when-both-records-are-same/m-p/238381#M43796</link>
      <description>&lt;P&gt;This should eliminate your duplicates and keep the record with the max time:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data output;
input datea time customer$ amount;
informat datea yymmdd10. time time10. customer $10. amount 6.;
format datea yymmdd10. time time10. customer $10. amount 6.;
datalines;
2015-11-20 11:18:36 lucy 250
2015-11-20 11:21:09 lucy 250
;
run;

proc sort data=output;
by datea customer descending time;
run;

data want;
set output;
by datea customer descending time;
If First.customer;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Dec 2015 21:12:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retrieve-a-record-with-max-time-when-both-records-are-same/m-p/238381#M43796</guid>
      <dc:creator>dcruik</dc:creator>
      <dc:date>2015-12-08T21:12:06Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve a record with max time when both records are same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retrieve-a-record-with-max-time-when-both-records-are-same/m-p/238385#M43798</link>
      <description>&lt;P&gt;You pointed out that the &lt;SPAN&gt;&lt;EM&gt;amounts&lt;/EM&gt; are duplicated. So, would you want to keep both records if the amounts were different, say, 240 and 250?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;How would your data look like&amp;nbsp;if there had been two completely different transactions which happened to involve the same amount? For example, Lucy paid 250 for a pair of shoes and another 250 for a coat on the same day. Would it make sense to pick only one of these transactions?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Would you still want to pick only one of the two records if they were, say, 12 hours apart rather than only a few minutes?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;What if the first datetime was 2015-11-20 23:58:36 and the second was&amp;nbsp;2015-11-21&amp;nbsp;00:01:09? In this case, grouping &lt;FONT face="courier new,courier"&gt;by datea&lt;/FONT&gt; would separate them and both would be selected.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Dec 2015 21:46:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retrieve-a-record-with-max-time-when-both-records-are-same/m-p/238385#M43798</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-12-08T21:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve a record with max time when both records are same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retrieve-a-record-with-max-time-when-both-records-are-same/m-p/238393#M43803</link>
      <description>&lt;P&gt;hi ,&lt;/P&gt;
&lt;P&gt;what if the data is like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;datea&amp;nbsp;&amp;nbsp;&amp;nbsp; time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; customer&amp;nbsp; amount sssid&lt;BR /&gt;2015-11-20&amp;nbsp; 11:18:36.0000000&amp;nbsp;&amp;nbsp;lucy&amp;nbsp;&amp;nbsp; 250&amp;nbsp;&amp;nbsp;&amp;nbsp; xxx&lt;BR /&gt;2015-11-20&amp;nbsp; 11:21:09.0000000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lucy&amp;nbsp;&amp;nbsp; 250&amp;nbsp;&amp;nbsp;&amp;nbsp; xxx&lt;BR /&gt;2015-11-23&amp;nbsp; 11:20:35.0000000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lucy&amp;nbsp;&amp;nbsp; 500&amp;nbsp;&amp;nbsp;&amp;nbsp; xxx&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and output should be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;datea&amp;nbsp;&amp;nbsp;&amp;nbsp; time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; customer&amp;nbsp; amount sssid&lt;BR /&gt;2015-11-20&amp;nbsp; 11:21:09.0000000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lucy&amp;nbsp;&amp;nbsp; 250&amp;nbsp;&amp;nbsp;&amp;nbsp; xxx&lt;BR /&gt;2015-11-23&amp;nbsp; 11:20:35.0000000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lucy&amp;nbsp;&amp;nbsp; 500&amp;nbsp;&amp;nbsp;&amp;nbsp; xxx&lt;/P&gt;</description>
      <pubDate>Tue, 08 Dec 2015 22:16:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retrieve-a-record-with-max-time-when-both-records-are-same/m-p/238393#M43803</guid>
      <dc:creator>chennupriya</dc:creator>
      <dc:date>2015-12-08T22:16:29Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve a record with max time when both records are same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retrieve-a-record-with-max-time-when-both-records-are-same/m-p/238399#M43807</link>
      <description>&lt;P&gt;The concept is correct, use a sort and BY group processing. Sort such that for duplicate records the latest time is at the top and then take the first record for each group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=output;
by datea amount descending time;
run;

data want;
set output;
by datea amount;
if first.amount;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Dec 2015 22:38:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retrieve-a-record-with-max-time-when-both-records-are-same/m-p/238399#M43807</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-08T22:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve a record with max time when both records are same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retrieve-a-record-with-max-time-when-both-records-are-same/m-p/238430#M43810</link>
      <description>&lt;P&gt;If everything is the same except the time in those duplicates, then you can simply do:&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 datea, max(time) as time, customer, amount, sssid
from have
group by datea, customer, amount, sssid;
quit; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Dec 2015 02:10:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retrieve-a-record-with-max-time-when-both-records-are-same/m-p/238430#M43810</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-12-09T02:10:38Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve a record with max time when both records are same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retrieve-a-record-with-max-time-when-both-records-are-same/m-p/238504#M43822</link>
      <description>&lt;P&gt;If you have multiple datea values, then I would just modify the sort by variables and what you are using as the variable with your First. satement.&amp;nbsp; This would get you what you want with the updated data you provided:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input datea time customer$ amount sssid$;
informat datea yymmdd10. time time20. customer $10. amount 6. sssid $10.;
format datea yymmdd10. time time20. customer $10. amount 6. sssid $10.;
datalines;
2015-11-20 11:18:36 lucy 250 xxx
2015-11-20 11:21:09 lucy 250 xxx
2015-11-23 11:20:35 lucy 500 xxx
;
run;

proc sort data=have;
by customer datea descending time;
run;

data want;
set have;
by customer datea descending time;
If First.datea;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Dec 2015 14:28:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retrieve-a-record-with-max-time-when-both-records-are-same/m-p/238504#M43822</guid>
      <dc:creator>dcruik</dc:creator>
      <dc:date>2015-12-09T14:28:25Z</dc:date>
    </item>
  </channel>
</rss>

