<?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: proc sql-select one row by group with max date value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-select-one-row-by-group-with-max-date-value/m-p/893072#M352780</link>
    <description>&lt;PRE&gt;select distinct *...&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Use&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068/show-comments/false" target="_blank" rel="noopener"&gt;Maxim 1&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;and read here:&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/n0mo9ak7pmhfjhn1fw5crkp17jg0.htm#p02xamv18rad1rn16thonuc2iubx" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/n0mo9ak7pmhfjhn1fw5crkp17jg0.htm#p02xamv18rad1rn16thonuc2iubx&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 07 Sep 2023 05:34:03 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2023-09-07T05:34:03Z</dc:date>
    <item>
      <title>proc sql-select one row by group with max date value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-select-one-row-by-group-with-max-date-value/m-p/893070#M352778</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to use proc sql to select one row by group.&lt;/P&gt;
&lt;P&gt;The criteria is to select&amp;nbsp; for each group the row with max value of date.&lt;/P&gt;
&lt;P&gt;However, if there are multiple rows with max date value then this query is not working well because it select multiple rows by group.&lt;/P&gt;
&lt;P&gt;What is the way to solve it via proc sql?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $ date : date9. var;
format date date9.;
cards;
B 05JAN2023 5
D 24JAN2023 2
B 06JAN2023 6
B 06JAN2023 6
B 06JAN2023 6
B 06JAN2023 6
C 15JAN2023 7
A 01JAN2023 10
C 16JAN2023 8
C 19JAN2023 9
C 20JAN2023 10
C 20JAN2023 10
C 20JAN2023 10
;
Run;

proc sql;
create table Way1 as
SELECT *
from have
group by ID
having date=max(date)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 05:23:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-select-one-row-by-group-with-max-date-value/m-p/893070#M352778</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-09-07T05:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql-select one row by group with max date value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-select-one-row-by-group-with-max-date-value/m-p/893072#M352780</link>
      <description>&lt;PRE&gt;select distinct *...&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Use&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068/show-comments/false" target="_blank" rel="noopener"&gt;Maxim 1&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;and read here:&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/n0mo9ak7pmhfjhn1fw5crkp17jg0.htm#p02xamv18rad1rn16thonuc2iubx" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/n0mo9ak7pmhfjhn1fw5crkp17jg0.htm#p02xamv18rad1rn16thonuc2iubx&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 05:34:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-select-one-row-by-group-with-max-date-value/m-p/893072#M352780</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-09-07T05:34:03Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql-select one row by group with max date value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-select-one-row-by-group-with-max-date-value/m-p/893075#M352783</link>
      <description>&lt;P&gt;Great&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
SELECT distinct *
from have
group by ID
having date=max(date)
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Sep 2023 05:49:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-select-one-row-by-group-with-max-date-value/m-p/893075#M352783</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-09-07T05:49:59Z</dc:date>
    </item>
  </channel>
</rss>

