<?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: Using PROC SQL MAX and Group by Function to select oldest date. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-SQL-MAX-and-Group-by-Function-to-select-oldest-date/m-p/895390#M353765</link>
    <description>&lt;P&gt;The oldest date and the MAX date are two different things.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you want to do this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Specimendate_all :mmddyy10. Patient_ID $ Pending $;
format Specimendate_all mmddyy10.;
infile datalines dlm = ',' missover;
datalines;
03/29/22,AB1,NO  
03/29/22,AB1,NO  
03/29/22,AB1,YES 
03/29/22,AB1,NO  
04/05/22,AB1,NO  
04/05/22,AB1,YES 
04/05/22,AB1,YES 
04/05/22,AB1,NO  
;


proc sql;
   create table want as
   select *, max(Specimendate_all) as specimenpendingmax format = mmddyy10.
   from have
   ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 22 Sep 2023 07:21:05 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2023-09-22T07:21:05Z</dc:date>
    <item>
      <title>Using PROC SQL MAX and Group by Function to select oldest date.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-SQL-MAX-and-Group-by-Function-to-select-oldest-date/m-p/895389#M353764</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a small subset of patient data that that includes all their specimen dates. I also have a Pending column where some rows are associated with a "YES" for the Pending column. However I want to create a new column with a "Pending Max Date" where it takes the oldest date in their specimen date and repeats for all their rows so that I can compare the dates for an exclusion.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was thinking of using Proc SQL and using the max and group by function but I have little experience with proc sql so any help would be great!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is what i'd like my table to look like.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Specimendate_all&lt;/TD&gt;&lt;TD&gt;&lt;SPAN&gt;Patient_ID&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD&gt;Pending&lt;/TD&gt;&lt;TD&gt;specimen pending max&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3/29/22&lt;/TD&gt;&lt;TD&gt;AB1&lt;/TD&gt;&lt;TD&gt;NO&lt;/TD&gt;&lt;TD&gt;4/5/22&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3/29/22&lt;/TD&gt;&lt;TD&gt;AB1&lt;/TD&gt;&lt;TD&gt;NO&lt;/TD&gt;&lt;TD&gt;4/5/22&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3/29/22&lt;/TD&gt;&lt;TD&gt;AB1&lt;/TD&gt;&lt;TD&gt;YES&lt;/TD&gt;&lt;TD&gt;4/5/22&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3/29/22&lt;/TD&gt;&lt;TD&gt;AB1&lt;/TD&gt;&lt;TD&gt;NO&lt;/TD&gt;&lt;TD&gt;4/5/22&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4/5/22&lt;/TD&gt;&lt;TD&gt;AB1&lt;/TD&gt;&lt;TD&gt;NO&lt;/TD&gt;&lt;TD&gt;4/5/22&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4/5/22&lt;/TD&gt;&lt;TD&gt;AB1&lt;/TD&gt;&lt;TD&gt;YES&lt;/TD&gt;&lt;TD&gt;4/5/22&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4/5/22&lt;/TD&gt;&lt;TD&gt;AB1&lt;/TD&gt;&lt;TD&gt;YES&lt;/TD&gt;&lt;TD&gt;4/5/22&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4/5/22&lt;/TD&gt;&lt;TD&gt;AB1&lt;/TD&gt;&lt;TD&gt;NO&lt;/TD&gt;&lt;TD&gt;4/5/22&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 22 Sep 2023 07:14:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-PROC-SQL-MAX-and-Group-by-Function-to-select-oldest-date/m-p/895389#M353764</guid>
      <dc:creator>rebelde52</dc:creator>
      <dc:date>2023-09-22T07:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using PROC SQL MAX and Group by Function to select oldest date.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-SQL-MAX-and-Group-by-Function-to-select-oldest-date/m-p/895390#M353765</link>
      <description>&lt;P&gt;The oldest date and the MAX date are two different things.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you want to do this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Specimendate_all :mmddyy10. Patient_ID $ Pending $;
format Specimendate_all mmddyy10.;
infile datalines dlm = ',' missover;
datalines;
03/29/22,AB1,NO  
03/29/22,AB1,NO  
03/29/22,AB1,YES 
03/29/22,AB1,NO  
04/05/22,AB1,NO  
04/05/22,AB1,YES 
04/05/22,AB1,YES 
04/05/22,AB1,NO  
;


proc sql;
   create table want as
   select *, max(Specimendate_all) as specimenpendingmax format = mmddyy10.
   from have
   ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Sep 2023 07:21:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-PROC-SQL-MAX-and-Group-by-Function-to-select-oldest-date/m-p/895390#M353765</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2023-09-22T07:21:05Z</dc:date>
    </item>
    <item>
      <title>Re: Using PROC SQL MAX and Group by Function to select oldest date.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-SQL-MAX-and-Group-by-Function-to-select-oldest-date/m-p/895391#M353766</link>
      <description>&lt;P&gt;It looks like you want the newest date, not the oldest...?&lt;/P&gt;
&lt;P&gt;Untested:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table want as
      select *,
               max(case pending when 'YES' then specimentdata_all else 0 end) as specimen_pending_max
      from have
      group by patient_id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2023 07:22:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-PROC-SQL-MAX-and-Group-by-Function-to-select-oldest-date/m-p/895391#M353766</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2023-09-22T07:22:54Z</dc:date>
    </item>
  </channel>
</rss>

