<?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: PROC SQL DATES sorting wrong? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-DATES-sorting-wrong/m-p/749191#M235371</link>
    <description>&lt;P&gt;RAWDTC2 is a string, therefore April comes before February.&lt;/P&gt;
&lt;P&gt;Replace&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;rawdtc2=put(input(rawdtc,E8601DA10.),date10.);&lt;/LI-CODE&gt;
&lt;P&gt;with&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;rawdtc2=input(rawdtc,E8601DA10.);&lt;/LI-CODE&gt;
&lt;P&gt;to have a date&lt;/P&gt;</description>
    <pubDate>Mon, 21 Jun 2021 06:46:45 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2021-06-21T06:46:45Z</dc:date>
    <item>
      <title>PROC SQL DATES sorting wrong?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-DATES-sorting-wrong/m-p/749189#M235369</link>
      <description>&lt;P&gt;Hi, how do I use min() and max() function in PROC SQL to get the right dates (&lt;STRONG&gt;earliest&lt;/STRONG&gt; and &lt;STRONG&gt;latest&lt;/STRONG&gt; dates) from a list of visit dates?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I feel like my code is right, but I'm getting a&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;format&lt;/EM&gt;&lt;/STRONG&gt;&lt;STRONG&gt; wrong.&amp;nbsp;PROC SQL&amp;nbsp;&lt;/STRONG&gt;is using the min/max functions correctly within the&amp;nbsp;&lt;STRONG&gt;&lt;U&gt;same&lt;/U&gt;&lt;/STRONG&gt; months (02FEB2009 is less than 19FEB2009), but the functions mess up when the months are different (02NOV2009 is&amp;nbsp;&lt;EM&gt;incorrectly less than&lt;/EM&gt; 10OCT2009).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help!!! A million thanks to the wonderful SAS community&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options fmtsearch=(lookup);
data aggreg;
	set svisit1-svisit&amp;amp;vars;
	by USUBJID VISITNUM rawdtc;
	VISIT=put(compress(put(VISITNUM,3.)),$VISITPRJ5457_VISIT.);
	rawdtc2=put(input(rawdtc,E8601DA10.),date10.);
	run;
	
proc sort data=aggreg out=aggreg2;
by USUBJID VISIT rawdtc2;

Proc sql;
create table xo as 
select USUBJID, VISIT, VISITNUM, rawdtc2,
 min(rawdtc2) as min_date,
 max(rawdtc2) as max_date 
from aggreg2
group by USUBJID, VISIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Jun 2021 06:41:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-DATES-sorting-wrong/m-p/749189#M235369</guid>
      <dc:creator>anonymous_user</dc:creator>
      <dc:date>2021-06-21T06:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL DATES sorting wrong?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-DATES-sorting-wrong/m-p/749191#M235371</link>
      <description>&lt;P&gt;RAWDTC2 is a string, therefore April comes before February.&lt;/P&gt;
&lt;P&gt;Replace&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;rawdtc2=put(input(rawdtc,E8601DA10.),date10.);&lt;/LI-CODE&gt;
&lt;P&gt;with&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;rawdtc2=input(rawdtc,E8601DA10.);&lt;/LI-CODE&gt;
&lt;P&gt;to have a date&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 06:46:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-DATES-sorting-wrong/m-p/749191#M235371</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-06-21T06:46:45Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL DATES sorting wrong?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-DATES-sorting-wrong/m-p/749193#M235373</link>
      <description>&lt;P&gt;Thank you so much!!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've been staring at this error for an hour.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So grateful for your quick help&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":dog:"&gt;🐕&lt;/span&gt;!!!&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 07:22:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-DATES-sorting-wrong/m-p/749193#M235373</guid>
      <dc:creator>anonymous_user</dc:creator>
      <dc:date>2021-06-21T07:22:05Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL DATES sorting wrong?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-DATES-sorting-wrong/m-p/749264#M235407</link>
      <description>&lt;P&gt;@anonymous_user, glad it is now working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For best practice and further appreciation, you should be able to accept the response from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;as the solution (not my post).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 14:32:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-DATES-sorting-wrong/m-p/749264#M235407</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2021-06-21T14:32:00Z</dc:date>
    </item>
  </channel>
</rss>

