<?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: How do I select one row based on max value with more than one grouping variable/column? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-one-row-based-on-max-value-with-more-than-one/m-p/790630#M253156</link>
    <description>&lt;P&gt;Worked very well.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just prefer some sql atm. Thanks for the help!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 18 Jan 2022 07:24:07 GMT</pubDate>
    <dc:creator>Pili1100</dc:creator>
    <dc:date>2022-01-18T07:24:07Z</dc:date>
    <item>
      <title>How do I select one row based on max value with more than one grouping variable/column?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-one-row-based-on-max-value-with-more-than-one/m-p/790582#M253139</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to get the maximum datetime per customer-id (C_ID) and per store. How do I do it?&lt;/P&gt;
&lt;P&gt;By.first and/or SQL max + grouping?&lt;/P&gt;
&lt;P&gt;Many thanks&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Ex.*/
DATA WORK.have;
FORMAT datetime datetime.;
INFILE DATALINES DELIMITER =','; 
INPUT C_ID $ store_nme $ datetime datetime.  ;
CARDS; 
AB,Store 1,17JAN2022:17:45:44
AB,Store 1,15JAN2021:17:55:40
AB,Store 1,25JAN2021:20:00:00
AB,Store 2,31OCT2020:12:00:01
AB,Store 2,05FEB2019:17:46:44
AB,Store 3,01AUG2021:16:02:16
AB,Store 3,01AUG2021:16:00:25
CD,Store 1,07MAR2019:03:12:11
CD,Store 1,11DEC2020:05:07:08
CD,Store 2,28DEC2020:12:00:01
CD,Store 2,28DEC2020:12:01:11
;
RUN;


PROC SORT DATA=have;
BY C_ID store_nme descending datetime ;
RUN;
DATA want;
SET have;
row_want = _N_;
IF row_WANT IN (1,4,6,8,10);
RUN; 
&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;</description>
      <pubDate>Mon, 17 Jan 2022 19:57:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-one-row-based-on-max-value-with-more-than-one/m-p/790582#M253139</guid>
      <dc:creator>Pili1100</dc:creator>
      <dc:date>2022-01-17T19:57:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do I select one row based on max value with more than one grouping variable/column?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-one-row-based-on-max-value-with-more-than-one/m-p/790584#M253140</link>
      <description>&lt;P&gt;PROC MEANS?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=have MAX NWAY;
class C_ID store_nme;
var datetime;
output out=want max(datetime) = max_datetime;
run;

proc print data=want;
format max_datetime datetime.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/363831"&gt;@Pili1100&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to get the maximum datetime per customer-id (C_ID) and per store. How do I do it?&lt;/P&gt;
&lt;P&gt;By.first and/or SQL max + grouping?&lt;/P&gt;
&lt;P&gt;Many thanks&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Ex.*/
DATA WORK.have;
FORMAT datetime datetime.;
INFILE DATALINES DELIMITER =','; 
INPUT C_ID $ store_nme $ datetime datetime.  ;
CARDS; 
AB,Store 1,17JAN2022:17:45:44
AB,Store 1,15JAN2021:17:55:40
AB,Store 1,25JAN2021:20:00:00
AB,Store 2,31OCT2020:12:00:01
AB,Store 2,05FEB2019:17:46:44
AB,Store 3,01AUG2021:16:02:16
AB,Store 3,01AUG2021:16:00:25
CD,Store 1,07MAR2019:03:12:11
CD,Store 1,11DEC2020:05:07:08
CD,Store 2,28DEC2020:12:00:01
CD,Store 2,28DEC2020:12:01:11
;
RUN;


PROC SORT DATA=have;
BY C_ID store_nme descending datetime ;
RUN;
DATA want;
SET have;
row_want = _N_;
IF row_WANT IN (1,4,6,8,10);
RUN; 
&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;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jan 2022 20:02:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-one-row-based-on-max-value-with-more-than-one/m-p/790584#M253140</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-01-17T20:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: How do I select one row based on max value with more than one grouping variable/column?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-one-row-based-on-max-value-with-more-than-one/m-p/790594#M253144</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc SQL;
Create table want as
select C_ID,store_nme , datetime
from have
group by 1,2
having datetime = max(datetime);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Jan 2022 20:44:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-one-row-based-on-max-value-with-more-than-one/m-p/790594#M253144</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2022-01-17T20:44:44Z</dc:date>
    </item>
    <item>
      <title>Re: How do I select one row based on max value with more than one grouping variable/column?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-one-row-based-on-max-value-with-more-than-one/m-p/790629#M253155</link>
      <description>&lt;P&gt;Thank you so much.&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jan 2022 07:23:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-one-row-based-on-max-value-with-more-than-one/m-p/790629#M253155</guid>
      <dc:creator>Pili1100</dc:creator>
      <dc:date>2022-01-18T07:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: How do I select one row based on max value with more than one grouping variable/column?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-one-row-based-on-max-value-with-more-than-one/m-p/790630#M253156</link>
      <description>&lt;P&gt;Worked very well.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just prefer some sql atm. Thanks for the help!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jan 2022 07:24:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-one-row-based-on-max-value-with-more-than-one/m-p/790630#M253156</guid>
      <dc:creator>Pili1100</dc:creator>
      <dc:date>2022-01-18T07:24:07Z</dc:date>
    </item>
  </channel>
</rss>

