<?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: Keeping the latest by group? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Keeping-the-latest-by-group/m-p/457596#M116029</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;

input cust_num acct_num date :yymmdd10. score_ID;
format date yymmdd10.; 
cards;
1 111 20150324 40000
1 111 20150324 50000
1 111 20150324 60000
1 111 20150324 70000
1 111 20150324 80000
1 111 20150402 40000
1 111 20150402 50000
1 111 20150402 60000
1 111 20150402 70000
1 111 20150402 80000
1 111 20150425 40000
1 111 20150425 50000
1 111 20150425 60000
1 111 20150425 70000
1 111 20150425 80000
2 222 20180302 70000
2 222 20180302 90000
;

run;

proc sql;
create table want as
select *
from have
group by cust_num, acct_num
having date=max(date);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 26 Apr 2018 02:43:59 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-04-26T02:43:59Z</dc:date>
    <item>
      <title>Keeping the latest by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-the-latest-by-group/m-p/457595#M116028</link>
      <description>&lt;P&gt;/*Hi SAS Forum,&lt;/P&gt;&lt;P&gt;I have posted this same question in another forum but due to urgency I posted it here too (apologies).&lt;/P&gt;&lt;P&gt;I have over million records dataset like this.&lt;/P&gt;&lt;P&gt;In this, same cust_num (that is 1) together with same acct_num (that is 111) occur three times&lt;/P&gt;&lt;P&gt;and make three by-groups.&lt;/P&gt;&lt;P&gt;And there is a single other by group related to acct 222.*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input cust_num acct_num date score_ID;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 111 20150324 40000&lt;/P&gt;&lt;P&gt;1 111 20150324 50000&lt;/P&gt;&lt;P&gt;1 111 20150324 60000&lt;/P&gt;&lt;P&gt;1 111 20150324 70000&lt;/P&gt;&lt;P&gt;1 111 20150324 80000&lt;/P&gt;&lt;P&gt;1 111 20150402 40000&lt;/P&gt;&lt;P&gt;1 111 20150402 50000&lt;/P&gt;&lt;P&gt;1 111 20150402 60000&lt;/P&gt;&lt;P&gt;1 111 20150402 70000&lt;/P&gt;&lt;P&gt;1 111 20150402 80000&lt;/P&gt;&lt;P&gt;1 111 20150425 40000&lt;/P&gt;&lt;P&gt;1 111 20150425 50000&lt;/P&gt;&lt;P&gt;1 111 20150425 60000&lt;/P&gt;&lt;P&gt;1 111 20150425 70000&lt;/P&gt;&lt;P&gt;1 111 20150425 80000&lt;/P&gt;&lt;P&gt;2 222 20180302 70000&lt;/P&gt;&lt;P&gt;2 222 20180302 90000&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Q: I need to keep only the latest by group.&lt;/P&gt;&lt;P&gt;Answer data set should be this because 20150425 is the latest date out of the three by groups for acct 111.&lt;/P&gt;&lt;P&gt;And three is a single other by group for acct 222.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 111 20150425 40000&lt;/P&gt;&lt;P&gt;1 111 20150425 50000&lt;/P&gt;&lt;P&gt;1 111 20150425 60000&lt;/P&gt;&lt;P&gt;1 111 20150425 70000&lt;/P&gt;&lt;P&gt;1 111 20150425 80000&lt;/P&gt;&lt;P&gt;2 222 20180302 70000&lt;/P&gt;&lt;P&gt;2 222 20180302 90000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please help me to do the coding. We should not use any hard coding like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if date = 20150425;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;because I do not know what are the latest dates in other million records&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mirisa&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*/&lt;/P&gt;</description>
      <pubDate>Thu, 26 Apr 2018 02:23:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-the-latest-by-group/m-p/457595#M116028</guid>
      <dc:creator>dunga</dc:creator>
      <dc:date>2018-04-26T02:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping the latest by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-the-latest-by-group/m-p/457596#M116029</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;

input cust_num acct_num date :yymmdd10. score_ID;
format date yymmdd10.; 
cards;
1 111 20150324 40000
1 111 20150324 50000
1 111 20150324 60000
1 111 20150324 70000
1 111 20150324 80000
1 111 20150402 40000
1 111 20150402 50000
1 111 20150402 60000
1 111 20150402 70000
1 111 20150402 80000
1 111 20150425 40000
1 111 20150425 50000
1 111 20150425 60000
1 111 20150425 70000
1 111 20150425 80000
2 222 20180302 70000
2 222 20180302 90000
;

run;

proc sql;
create table want as
select *
from have
group by cust_num, acct_num
having date=max(date);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Apr 2018 02:43:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-the-latest-by-group/m-p/457596#M116029</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-04-26T02:43:59Z</dc:date>
    </item>
  </channel>
</rss>

