<?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: Getting max from a date in proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Getting-max-from-a-date-in-proc-sql/m-p/743468#M232787</link>
    <description>&lt;P&gt;A lot of people will label a variable that contains DATETIME values with a name like DATE1.&lt;/P&gt;
&lt;P&gt;Try either using a DATETIME format on the MAX() value.&lt;/P&gt;
&lt;P&gt;Or use the DATEPART() function to convert the datetime values (number of seconds) into date values (number of days) and then you can use the DATE format to display the values in a human recognizable string.&lt;/P&gt;</description>
    <pubDate>Tue, 25 May 2021 04:30:32 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-05-25T04:30:32Z</dc:date>
    <item>
      <title>Getting max from a date in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-max-from-a-date-in-proc-sql/m-p/743459#M232781</link>
      <description>&lt;P&gt;Hi experts, I have this code:&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE my_table AS&lt;BR /&gt;SELECT DISTINCT&lt;BR /&gt;MAX(T1.sequential) AS num,&lt;BR /&gt;MAX(T1.date1) AS pay_date format date9.,&lt;BR /&gt;T1.sec AS sequential&lt;/P&gt;&lt;P&gt;FROM table_one T1, table_two T2&lt;BR /&gt;WHERE T1.number_A = T2.number_A&lt;BR /&gt;GROUP BY T1.name;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;and i obtain this : ******&amp;nbsp; in the max of the date, the format (date9.) does not work&lt;/P&gt;&lt;P&gt;num&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;pay_date&amp;nbsp; &amp;nbsp;sequential&amp;nbsp;&lt;/P&gt;&lt;P&gt;3375414&amp;nbsp; &amp;nbsp;*********&amp;nbsp; &amp;nbsp;24025521&lt;/P&gt;</description>
      <pubDate>Tue, 25 May 2021 02:19:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-max-from-a-date-in-proc-sql/m-p/743459#M232781</guid>
      <dc:creator>Jose7</dc:creator>
      <dc:date>2021-05-25T02:19:40Z</dc:date>
    </item>
    <item>
      <title>Re: Getting max from a date in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-max-from-a-date-in-proc-sql/m-p/743460#M232782</link>
      <description>Sorry the group by is T1.sec</description>
      <pubDate>Tue, 25 May 2021 02:21:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-max-from-a-date-in-proc-sql/m-p/743460#M232782</guid>
      <dc:creator>Jose7</dc:creator>
      <dc:date>2021-05-25T02:21:28Z</dc:date>
    </item>
    <item>
      <title>Re: Getting max from a date in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-max-from-a-date-in-proc-sql/m-p/743468#M232787</link>
      <description>&lt;P&gt;A lot of people will label a variable that contains DATETIME values with a name like DATE1.&lt;/P&gt;
&lt;P&gt;Try either using a DATETIME format on the MAX() value.&lt;/P&gt;
&lt;P&gt;Or use the DATEPART() function to convert the datetime values (number of seconds) into date values (number of days) and then you can use the DATE format to display the values in a human recognizable string.&lt;/P&gt;</description>
      <pubDate>Tue, 25 May 2021 04:30:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-max-from-a-date-in-proc-sql/m-p/743468#M232787</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-25T04:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: Getting max from a date in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-max-from-a-date-in-proc-sql/m-p/743470#M232788</link>
      <description>&lt;P&gt;A display of ******* typically means that the value of the variable exceeds what the format is designed to work with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the format of the variable Date1 in Table_one? If you see something like BEST12 then your "date" likely is just a number that you have thought was a "date".&lt;/P&gt;
&lt;P&gt;Run Proc contents on Table_one and share the result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example of what I think might be going on since you have not shared any actual value:&lt;/P&gt;
&lt;PRE&gt;data example;
    date = 20200715; /* you might think this is 15Jul2020*/
   put date=  date9.;
run;

/* which the log will show */
137  data example;
138      date = 20200715; /* you might think this is 15Jul2020*/
139     put date=  date9.;
140  run;

date=*********
&lt;/PRE&gt;
&lt;P&gt;The 9 asterisks are because the format is 9 characters wide.&lt;/P&gt;
&lt;P&gt;And how to get an actual date from that sort of number:&lt;/P&gt;
&lt;PRE&gt;data example2;
   date = 20200715;
   actualdate = input(put(date,f8. -L),yymmdd10.);
   put actualdate date9.;
run;
/* which in the log shows*/
142  data example2;
143     date = 20200715;
144     actualdate = input(put(date,f8. -L),yymmdd10.);
145     put actualdate= date9.;
146  run;

actualdate=15JUL2020
&lt;/PRE&gt;
&lt;P&gt;SAS date values are the number of days since 1 Jan 1960. So the SAS date value in the example2 is 22111. If you have values like 20200715 you exceed the number of days SAS has defined formats and values for dates. The largest date SAS supports is 31 December 20,000 (yes year twentythousand) which is a number of 6589335. So any number larger than that is an invalid "date" as far as SAS is concerned, as is any date prior to 1582.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt; has a PDF with much information about dates.&lt;/P&gt;</description>
      <pubDate>Tue, 25 May 2021 04:39:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-max-from-a-date-in-proc-sql/m-p/743470#M232788</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-25T04:39:50Z</dc:date>
    </item>
  </channel>
</rss>

