<?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: Find and recognize the max(date)record from a random list of records in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-and-recognize-the-max-date-record-from-a-random-list-of/m-p/811540#M320113</link>
    <description>&lt;P&gt;Use a double DO loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do until (last.toolid);
  set have;
  by toolid;
  maxdate = max(maxdate,date);
end;
do until (last.toolid);
  set have;
  by toolid;
  if date = maxdate then flag = 1;
  output;
end;
drop maxdate;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 04 May 2022 19:18:34 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-05-04T19:18:34Z</dc:date>
    <item>
      <title>Find and recognize the max(date)record from a random list of records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-and-recognize-the-max-date-record-from-a-random-list-of/m-p/811535#M320111</link>
      <description>&lt;P&gt;Greetings,&lt;/P&gt;&lt;P&gt;I am trying to update an existing record set so I can update a flag for the most recent entry that can be used for reporting purposes and I have hit a wall and need help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have, and cannot alter, data in this format although it is a bit more random in the order:&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;data work.records;
    input ToolID Date $ Outcome $ Flag;
    datalines;
12345 01/01/2022 Pass 0
12345 04/01/2022 Fail 0
12345 02/01/2022 Fail 0
12345 12/01/2021 Pass 0
12345 03/01/2022 Pass 0
98765 03/01/2022 Fail 0
98765 02/01/2022 Pass 0
65471 02/01/2022 Fail 0
;
run; &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;What I need to do is update the flag to be equal to 1 where it is the records max(date)&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;data work.records;
    input ToolID Date $ Outcome $ Flag;
    datalines;
12345 01/01/2022 Pass 0
12345 04/01/2022 Fail 1
12345 02/01/2022 Fail 0
12345 12/01/2021 Pass 0
12345 03/01/2022 Pass 0
98765 03/01/2022 Fail 1
98765 02/01/2022 Pass 0
65471 02/01/2022 Fail 1
;
run; &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;I have tried creating a temp table and hold the max date and tool id, but I keep hitting a wall on how to update the flag.&amp;nbsp; Nothing I have tried has been successful at doing the update, but that makes sense as I am only so so when it comes to SAS programming and I tend to use the PROC SQL more then anything else.&lt;BR /&gt;&lt;BR /&gt;There has to be a simple way to do this!&amp;nbsp; HELP!!&lt;/DIV&gt;</description>
      <pubDate>Wed, 04 May 2022 18:42:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-and-recognize-the-max-date-record-from-a-random-list-of/m-p/811535#M320111</guid>
      <dc:creator>heraldic2</dc:creator>
      <dc:date>2022-05-04T18:42:11Z</dc:date>
    </item>
    <item>
      <title>Re: Find and recognize the max(date)record from a random list of records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-and-recognize-the-max-date-record-from-a-random-list-of/m-p/811540#M320113</link>
      <description>&lt;P&gt;Use a double DO loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do until (last.toolid);
  set have;
  by toolid;
  maxdate = max(maxdate,date);
end;
do until (last.toolid);
  set have;
  by toolid;
  if date = maxdate then flag = 1;
  output;
end;
drop maxdate;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 May 2022 19:18:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-and-recognize-the-max-date-record-from-a-random-list-of/m-p/811540#M320113</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-05-04T19:18:34Z</dc:date>
    </item>
    <item>
      <title>Re: Find and recognize the max(date)record from a random list of records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-and-recognize-the-max-date-record-from-a-random-list-of/m-p/811541#M320114</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.records;
    input ToolID Date :mmddyy10. Outcome $;
    datalines;
12345 01/01/2022 Pass 0
12345 04/01/2022 Fail 0
12345 02/01/2022 Fail 0
12345 12/01/2021 Pass 0
12345 03/01/2022 Pass 0
98765 03/01/2022 Fail 0
98765 02/01/2022 Pass 0
65471 02/01/2022 Fail 0
;
run; 

proc sql;
    create table want as select *,date=max(date) as flag
    from records
    group by toolid;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 May 2022 19:02:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-and-recognize-the-max-date-record-from-a-random-list-of/m-p/811541#M320114</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-04T19:02:09Z</dc:date>
    </item>
    <item>
      <title>Re: Find and recognize the max(date)record from a random list of records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-and-recognize-the-max-date-record-from-a-random-list-of/m-p/811553#M320121</link>
      <description>&lt;P&gt;Thank you very much.&amp;nbsp; I was able to get this to work quite easily and learned about the MAX() function.&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 20:19:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-and-recognize-the-max-date-record-from-a-random-list-of/m-p/811553#M320121</guid>
      <dc:creator>heraldic2</dc:creator>
      <dc:date>2022-05-04T20:19:07Z</dc:date>
    </item>
  </channel>
</rss>

