<?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: Select top 1 (highest value )per section and day in SAS EG in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636457#M35781</link>
    <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That does not deal with all cases correctly. Feed it this data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $ Location $ Section $ Date :ddmmyy10. Time time5. Type $ Value :comma8.1;
format Time hhmm5.;
format Date ddmmyy10.;
datalines;
01 Germany BB 1/1/20 10:10 VW 9,0
02 Germany AA 1/1/20 11:20 AU 7,0
03 Germany AA 1/1/20 13:50 AU 6,0
04 Germany BB 1/1/20 13:50 AU 10,7
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and you'll get two entries for BB instead of only one.&lt;/P&gt;</description>
    <pubDate>Wed, 01 Apr 2020 07:31:45 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-04-01T07:31:45Z</dc:date>
    <item>
      <title>Select top 1 (highest value )per section and day in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636446#M35773</link>
      <description>&lt;P&gt;Hello All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I might ask an easy question but I want the following. I want to select the &lt;STRONG&gt;top 1&lt;/STRONG&gt; highest value per &lt;STRONG&gt;SECTION&lt;/STRONG&gt; and per &lt;STRONG&gt;DAY&lt;/STRONG&gt;. Please see the example below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*This is the data I have right now (with thousands of rows)&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;ID -- Location -- Section -- Date -- Time -- Type -- Value&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;01 -- Germany -- BB&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--&lt;STRONG&gt;1/1/20&lt;/STRONG&gt; -- 10:10 -- VW --&amp;nbsp; &amp;nbsp;9,0&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;02 -- Germany -- AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--&lt;STRONG&gt;1/1/20&lt;/STRONG&gt; -- 11:20 -- AU --&amp;nbsp; &amp;nbsp; 7,0&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;03 -- Germany -- AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--&lt;STRONG&gt;1/1/20&lt;/STRONG&gt; -- 13:50 -- AU --&amp;nbsp; &amp;nbsp; 6,0&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;04 -- Germany -- BB&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--&lt;STRONG&gt;1/1/20&lt;/STRONG&gt; -- 13:50 -- AU --&amp;nbsp; &amp;nbsp; 5,7&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;05 -- Germany -- BB&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--&lt;STRONG&gt;2/1/20&lt;/STRONG&gt; -- 15:10 -- MC --&amp;nbsp; 11,3&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;06 -- Germany -- BB&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--&lt;STRONG&gt;2/1/20&lt;/STRONG&gt; -- 19:10 -- VW --&amp;nbsp; 12,0&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;07 -- Germany -- AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--&lt;STRONG&gt;2/1/20&lt;/STRONG&gt; -- 15:20 -- OP --&amp;nbsp; &amp;nbsp; 6,7&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;08 -- Germany -- AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--&lt;STRONG&gt;2/1/20&lt;/STRONG&gt; -- 15:20 -- AU --&amp;nbsp; &amp;nbsp; 2,0&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;09 -- Germany -- BB&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--&lt;STRONG&gt;3/1/20&lt;/STRONG&gt; -- 16:16 -- MC --&amp;nbsp; &amp;nbsp;1,5&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;10 -- Germany -- BB&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--&lt;STRONG&gt;3/1/20&lt;/STRONG&gt; -- 11:45 -- MC --&amp;nbsp; &amp;nbsp;5,8&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;11 -- Germany -- AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--&lt;STRONG&gt;3/1/20&lt;/STRONG&gt; -- 09:40 -- OP --&amp;nbsp; &amp;nbsp;2,7&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;12 -- Germany -- AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--&lt;STRONG&gt;3/1/20&lt;/STRONG&gt; -- 02:40 -- VW --&amp;nbsp; &amp;nbsp;2,0&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*This is the data I want:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;ID -- Location -- Section -- Date -- Time -- Type -- Value&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;01 -- Germany -- BB&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--&lt;STRONG&gt;1/1/20&lt;/STRONG&gt; -- 10:10 -- VW --&amp;nbsp; &amp;nbsp;9,0&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;02 -- Germany -- AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--&lt;STRONG&gt;1/1/20&lt;/STRONG&gt; -- 11:20 -- AU --&amp;nbsp; &amp;nbsp; 7,0&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;06 -- Germany -- BB&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--&lt;STRONG&gt;2/1/20&lt;/STRONG&gt; -- 19:10 -- VW --&amp;nbsp; 12,0&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;07 -- Germany -- AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--&lt;STRONG&gt;2/1/20&lt;/STRONG&gt; -- 15:20 -- OP --&amp;nbsp; &amp;nbsp; &amp;nbsp;6,7&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;10 -- Germany -- BB&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--&lt;STRONG&gt;3/1/20&lt;/STRONG&gt; -- 11:45 -- MC --&amp;nbsp; &amp;nbsp; &amp;nbsp;5,8&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;11 -- Germany -- AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--&lt;STRONG&gt;3/1/20&lt;/STRONG&gt; -- 09:40 -- OP --&amp;nbsp; &amp;nbsp; &amp;nbsp;2,7&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate your help all &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Thank you in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Apr 2020 06:33:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636446#M35773</guid>
      <dc:creator>AK100</dc:creator>
      <dc:date>2020-04-01T06:33:04Z</dc:date>
    </item>
    <item>
      <title>Re: Select top 1 (highest value )per section and day in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636449#M35775</link>
      <description>&lt;P&gt;use proc means to get what you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=have;
   class location section date;
   var value;
   output out=want(drop=_type_ count) max=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Apr 2020 06:48:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636449#M35775</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-04-01T06:48:56Z</dc:date>
    </item>
    <item>
      <title>Re: Select top 1 (highest value )per section and day in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636451#M35776</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by section date descending value;
run;

data want;
set have;
by section date;
if first.date;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Apr 2020 06:52:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636451#M35776</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-01T06:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: Select top 1 (highest value )per section and day in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636452#M35777</link>
      <description>Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16120"&gt;@Kurt&lt;/a&gt;, your good. You made it look really simple!&lt;BR /&gt;&lt;BR /&gt;By the way. I'am still working on that conversion to data steps thing. I know it makes it easier for you guys to check the data and solve the problems. Hope I can use it soon.</description>
      <pubDate>Wed, 01 Apr 2020 07:02:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636452#M35777</guid>
      <dc:creator>AK100</dc:creator>
      <dc:date>2020-04-01T07:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: Select top 1 (highest value )per section and day in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636453#M35778</link>
      <description>It almost worked, but thank you in advance!</description>
      <pubDate>Wed, 01 Apr 2020 07:03:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636453#M35778</guid>
      <dc:creator>AK100</dc:creator>
      <dc:date>2020-04-01T07:03:18Z</dc:date>
    </item>
    <item>
      <title>Re: Select top 1 (highest value )per section and day in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636454#M35779</link>
      <description>&lt;P&gt;For a small dataset like yours, the data2datastep macro is not needed, it's easier to write the data step directly:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input
  ID :$2.
  Location :$10.
  Section :$2.
  Date :ddmmyy10.
  Time :time5.
  Type :$2.
  Value :commax10.
;
format
  date ddmmyyp10.
  time time5.
  value commax10.2
;
datalines;
01 Germany BB 1/1/20 10:10 VW 9,0
02 Germany AA 1/1/20 11:20 AU 7,0
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As I said, not rocket science at all.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Apr 2020 07:14:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636454#M35779</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-01T07:14:18Z</dc:date>
    </item>
    <item>
      <title>Re: Select top 1 (highest value )per section and day in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636455#M35780</link>
      <description>&lt;P&gt;Here, it is done in a single pass and with the desired result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $ Location $ Section $ Date :ddmmyy10. Time time5. Type $ Value :comma8.1;
format Time hhmm5.;
format Date ddmmyy10.;
datalines;
01 Germany BB 1/1/20 10:10 VW 9,0
02 Germany AA 1/1/20 11:20 AU 7,0
03 Germany AA 1/1/20 13:50 AU 6,0
04 Germany BB 1/1/20 13:50 AU 5,7
05 Germany BB 2/1/20 15:10 MC 11,3
06 Germany BB 2/1/20 19:10 VW 12,0
07 Germany AA 2/1/20 15:20 OP 6,7
08 Germany AA 2/1/20 15:20 AU 2,0
09 Germany BB 3/1/20 16:16 MC 1,5
10 Germany BB 3/1/20 11:45 MC 5,8
11 Germany AA 3/1/20 09:40 OP 2,7
12 Germany AA 3/1/20 02:40 VW 2,0
;

data want (drop=rc);
   if _N_ = 1 then do;
      declare hash h (dataset : 'have(obs=0)', ordered : 'd', multidata : 'y');
      h.definekey ('Section', 'Value');
      h.definedata (all : 'y');
      h.definedone();
      declare hiter hi ('h');
   end;

   do until (last.Section);
      set have;
      by Section notsorted Date;
      h.add();
   end;

   rc = hi.next();  
   output; 
   rc = hi.prev();
   h.clear();    
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ID Location Section Date       Time  Type Value 
01 Germany  BB      01/01/1920 10:10 VW   9.0 
02 Germany  AA      01/01/1920 11:20 AU   7.0 
06 Germany  BB      02/01/1920 19:10 VW   12.0 
07 Germany  AA      02/01/1920 15:20 OP   6.7 
10 Germany  BB      03/01/1920 11:45 MC   5.8 
11 Germany  AA      03/01/1920 9:40  OP   2.7 
&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Apr 2020 07:20:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636455#M35780</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-04-01T07:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: Select top 1 (highest value )per section and day in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636457#M35781</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That does not deal with all cases correctly. Feed it this data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $ Location $ Section $ Date :ddmmyy10. Time time5. Type $ Value :comma8.1;
format Time hhmm5.;
format Date ddmmyy10.;
datalines;
01 Germany BB 1/1/20 10:10 VW 9,0
02 Germany AA 1/1/20 11:20 AU 7,0
03 Germany AA 1/1/20 13:50 AU 6,0
04 Germany BB 1/1/20 13:50 AU 10,7
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and you'll get two entries for BB instead of only one.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Apr 2020 07:31:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636457#M35781</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-01T07:31:45Z</dc:date>
    </item>
    <item>
      <title>Re: Select top 1 (highest value )per section and day in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636458#M35782</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;isn't that what the OP&amp;nbsp;&lt;EM&gt;want&lt;/EM&gt;&amp;nbsp;data set implies?&lt;/P&gt;</description>
      <pubDate>Wed, 01 Apr 2020 07:40:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636458#M35782</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-04-01T07:40:20Z</dc:date>
    </item>
    <item>
      <title>Re: Select top 1 (highest value )per section and day in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636459#M35783</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;an other quick case, what if I not want to select the top 1 per SECTION and per DAY but the TOP 4 per SECTION and DAY and add like a RANKING column to show the ranking from 1-4. How will your code below look like then?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;proc sort data=have;
by section date descending value;
run;

data want;
set have;
by section date;
if first.date;
run;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Apr 2020 07:45:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636459#M35783</guid>
      <dc:creator>AK100</dc:creator>
      <dc:date>2020-04-01T07:45:12Z</dc:date>
    </item>
    <item>
      <title>Re: Select top 1 (highest value )per section and day in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636461#M35784</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;isn't that what the OP&amp;nbsp;&lt;EM&gt;want&lt;/EM&gt;&amp;nbsp;data set implies?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's only because the "have" dataset in the OP does not have one single case where a higher value follows later in the day, with another section appearing in between. That's why I subtly changed the input data to have this kind of "edge case".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The OP rule is "&lt;EM&gt;one&lt;/EM&gt; value for a combination of section and date", and the hash code throws two values for 01/01 and BB (with my changed data). You would need to fill the hash per date, then iterate through the whole hash object to get all firsts &lt;EM&gt;per section&lt;/EM&gt;, and then clear the hash to make the processing of the next day easier.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Apr 2020 07:55:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636461#M35784</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-01T07:55:56Z</dc:date>
    </item>
    <item>
      <title>Re: Select top 1 (highest value )per section and day in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636462#M35785</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/310659"&gt;@AK100&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;an other quick case, what if I not want to select the top 1 per SECTION and per DAY but the TOP 4 per SECTION and DAY and add like a RANKING column to show the ranking from 1-4. How will your code below look like then?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;proc sort data=have;
by section date descending value;
run;

data want;
set have;
by section date;
if first.date;
run;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's easy. At first.date, set a (retained) counter to 1 (instead of the &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=p1cxl8ifdt8u0gn12wqbji8o5fq1.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;subsetting if&lt;/A&gt; you have now), and increment it else. Use a subsetting if to only output when the counter is le 4.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Apr 2020 07:59:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636462#M35785</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-01T07:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: Select top 1 (highest value )per section and day in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636463#M35786</link>
      <description>&lt;P style="line-height: 1.71429; font-family: Arial, Helvetica, sans-serif;"&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;Okay, I just figured out this one (which also gives me the desired output). Is is the same as yours or does it look slightly different?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
	by section date descending value;
run;

data top4;
	set have;
	by section date;
	retain ranking;

	if first.date then
		ranking =0;
	ranking +1;

	if ranking &amp;lt;5;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;@&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Apr 2020 08:12:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636463#M35786</guid>
      <dc:creator>AK100</dc:creator>
      <dc:date>2020-04-01T08:12:00Z</dc:date>
    </item>
    <item>
      <title>Re: Select top 1 (highest value )per section and day in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636465#M35787</link>
      <description>&lt;P&gt;This looks good (and is valid), but I would do it slightly different:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data top4;
set have;
by section date;
if first.date
then ranking = 1;
else ranking + 1; /* when you use this type of increment statement, the variable is automatically retained */
if ranking le 4;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is purely a matter of "code cosmetics"; at first.date, there is one statement less to execute.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Apr 2020 08:17:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636465#M35787</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-01T08:17:17Z</dc:date>
    </item>
    <item>
      <title>Re: Select top 1 (highest value )per section and day in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636466#M35788</link>
      <description>Thank You &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Wed, 01 Apr 2020 08:19:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/636466#M35788</guid>
      <dc:creator>AK100</dc:creator>
      <dc:date>2020-04-01T08:19:35Z</dc:date>
    </item>
    <item>
      <title>Re: Select top 1 (highest value )per section and day in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/637192#M35802</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One more question. I now have a column with a ranking 1-4. I want to add an other column which shows just the value of the top 1 rank. The rank 2-4 should be blank. The orange column is the column I want to add. Because for further calculations in Visual Analytics I just need the top 1 ranking. Thank&amp;nbsp; you in advance &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;ID -- Location -- Section -- Date -- Time -- Type -- Value -- Ranking1-4 &lt;FONT color="#FF6600"&gt;-- Ranking1 (2-4)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;01 -- Germany -- AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--&lt;STRONG&gt;1/1/20&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;-- 10:10 -- VW --&amp;nbsp; &amp;nbsp;9,0&amp;nbsp; -- 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;FONT color="#FF6600"&gt;-- 9,0&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;02 -- Germany -- AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--&lt;STRONG&gt;1/1/20&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;-- 11:20 -- AU --&amp;nbsp; &amp;nbsp; 7,0&amp;nbsp; -- 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#FF6600"&gt;this should be blank&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;03 -- Germany -- AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--&lt;STRONG&gt;1/1/20&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;-- 13:50 -- AU --&amp;nbsp; &amp;nbsp; 6,0&amp;nbsp; --3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#FF6600"&gt;this should be blank&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;04 -- Germany -- AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; --&lt;STRONG&gt;1/1/20&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;-- 13:50 -- AU --&amp;nbsp; &amp;nbsp; 5,7&amp;nbsp; --4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;FONT color="#FF6600"&gt;this should be blank&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;05 -- Germany -- BB&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--1&lt;STRONG&gt;/1/20&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;-- 15:10 -- MC --&amp;nbsp; 15,3&amp;nbsp; --1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#FF6600"&gt; -- 15,3&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;06 -- Germany -- BB&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--1&lt;STRONG&gt;/1/20&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;-- 19:10 -- VW --&amp;nbsp; 12,0&amp;nbsp; --2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;FONT color="#FF6600"&gt;this should be blank&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;07 -- Germany -- BB&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--1&lt;STRONG&gt;/1/20&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;-- 15:20 -- OP --&amp;nbsp; &amp;nbsp; 6,7&amp;nbsp; --3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;FONT color="#FF6600"&gt;this should be blank&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;08 -- Germany -- BB&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--1&lt;STRONG&gt;/1/20&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;-- 15:20 -- AU --&amp;nbsp; &amp;nbsp; 2,0&amp;nbsp; --4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;FONT color="#FF6600"&gt;&amp;nbsp; this should be blank&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;09 -- Germany -- AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--2&lt;STRONG&gt;/1/20&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;-- 16:16 -- MC --&amp;nbsp; &amp;nbsp;9,5 --1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;FONT color="#FF6600"&gt;&amp;nbsp;--9,5&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;10 -- Germany -- AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--2&lt;STRONG&gt;/1/20&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;-- 11:45 -- MC --&amp;nbsp; &amp;nbsp;5,8 --2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;FONT color="#FF6600"&gt;&amp;nbsp;&amp;nbsp; this should be blank&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;11 -- Germany -- AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--2&lt;STRONG&gt;/1/20&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;-- 09:40 -- OP --&amp;nbsp; &amp;nbsp;2,7 --3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#FF6600"&gt;&amp;nbsp;&amp;nbsp; this should be blank&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;12 -- Germany -- AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--2&lt;STRONG&gt;/1/20&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;-- 02:40 -- VW --&amp;nbsp; &amp;nbsp;2,0 --4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#FF6600"&gt; this should be blank&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Apr 2020 10:19:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/637192#M35802</guid>
      <dc:creator>AK100</dc:creator>
      <dc:date>2020-04-03T10:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: Select top 1 (highest value )per section and day in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/637209#M35803</link>
      <description>&lt;P&gt;In the previous step I gave you, expand the "then" branch with do-end, and set ranking1 in the block (along with ranking = 1) to value.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Apr 2020 11:37:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/637209#M35803</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-03T11:37:41Z</dc:date>
    </item>
    <item>
      <title>Re: Select top 1 (highest value )per section and day in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/637244#M35804</link>
      <description>Can you show me how the code would look like?</description>
      <pubDate>Fri, 03 Apr 2020 12:45:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/637244#M35804</guid>
      <dc:creator>AK100</dc:creator>
      <dc:date>2020-04-03T12:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: Select top 1 (highest value )per section and day in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/637246#M35805</link>
      <description>&lt;P&gt;Just try your hand, it's not rocket science at all. I gave you all the information you need in my previous post.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Apr 2020 12:59:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-top-1-highest-value-per-section-and-day-in-SAS-EG/m-p/637246#M35805</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-03T12:59:31Z</dc:date>
    </item>
  </channel>
</rss>

