<?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: Compare the date with macro date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-date-with-macro-date/m-p/880455#M347882</link>
    <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;The macro variable &amp;amp;DatePublication is not a valid SAS date. It is the text string 13/06/2023. SAS does not recognize this as a date, even though humans do recognize this as a date.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Some humans might.&amp;nbsp; My calendar only has 12 months in a year so 13/06/2023 does not look like a date to me.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 13 Jun 2023 15:50:42 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-06-13T15:50:42Z</dc:date>
    <item>
      <title>Compare the date with macro date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-date-with-macro-date/m-p/880436#M347876</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I create the macro variable in this way :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let DatePublication = %sysfunc(today(), ddmmyy10.);
%put &amp;amp;DatePublication.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But when I apply this condition :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if datepart(d_fin) &amp;gt; &amp;amp;DatePublication.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Unfortunately, I don't have the right observation in output. Do I need apply another function?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I apply %eval it also doesn't work. The format of d_fin is&amp;nbsp;datetime22. format.&amp;nbsp;Thank you for your help.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if datepart(d_fin) &amp;gt; %eval(&amp;amp;DatePublication.)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Jun 2023 15:11:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-date-with-macro-date/m-p/880436#M347876</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2023-06-13T15:11:32Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the date with macro date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-date-with-macro-date/m-p/880439#M347877</link>
      <description>&lt;P&gt;In short you are not comparing apples to apples.&lt;BR /&gt;The macro variable DatePublication contains a formatted date (character value e.g. 13/06/2023)&lt;/P&gt;
&lt;P&gt;Whereas the datepart function is returning a &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/n0mnbmcjgwpiotn116oz5wtifwxa.htm" target="_self"&gt;SAS date value&lt;/A&gt; (numeric number of days since 01 Jan 1960) from a SAS date/time value&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run the following code in SAS and compare the log output&lt;BR /&gt;&lt;BR /&gt;Unless you have some reason for using the macro variable I would remove that additional complexity from the code (see 2nd data step in example below)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let DatePublication = %sysfunc(today(), ddmmyy10.); &lt;BR /&gt;%put &amp;amp;DatePublication.; &lt;BR /&gt;&lt;BR /&gt;data _null_ ; &lt;BR /&gt;  datetime=datetime() ; &lt;BR /&gt;  datepart=datepart(datetime) ; &lt;BR /&gt;  put datetime= ; &lt;BR /&gt;  put datepart= ; &lt;BR /&gt;run ; &lt;BR /&gt;&lt;BR /&gt;data _null_ ; &lt;BR /&gt;  datetime=datetime() ; &lt;BR /&gt;  datepart=datepart(datetime) ; &lt;BR /&gt;  do date=date()-1 to date()+1 ; &lt;BR /&gt;    if date&amp;gt;datepart(datetime) then &lt;BR /&gt;      put "Date " date " &amp;gt; DateTime " datetime " - DatePart " datepart ; &lt;BR /&gt;    else &lt;BR /&gt;      put "Date " date "&amp;lt;= DateTime " datetime " - DatePart " datepart ; &lt;BR /&gt;  end ; &lt;BR /&gt;run ; &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2023 15:27:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-date-with-macro-date/m-p/880439#M347877</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2023-06-13T15:27:08Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the date with macro date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-date-with-macro-date/m-p/880443#M347878</link>
      <description>&lt;P&gt;You just need to remove the format from your statement, try changing it to this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let DatePublication = %sysfunc(today()); &lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2023 15:22:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-date-with-macro-date/m-p/880443#M347878</guid>
      <dc:creator>russt_sas</dc:creator>
      <dc:date>2023-06-13T15:22:55Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the date with macro date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-date-with-macro-date/m-p/880445#M347880</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let DatePublication = %sysfunc(today(), ddmmyy10.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro variable &amp;amp;DatePublication is not a valid SAS date. It is the text string 13/06/2023. SAS does not recognize this as a date, even though humans do recognize this as a date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS dates are the number of days since 01JAN1960, and so SAS would recognize this as a valid SAS date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let DatePublication = %sysfunc(today());&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the value 23174, which is a valid SAS date. It is the number of days since 01JAN1960.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So when you compare a date value in your DATA step, SAS always uses its internal representation of the number of days since 01JAN1960. Thus if you use this particular &amp;amp;DatePublication, this should work in your DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 28&lt;/A&gt;: "Macro variables need no formats."&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2023 15:27:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-date-with-macro-date/m-p/880445#M347880</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-13T15:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the date with macro date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-date-with-macro-date/m-p/880455#M347882</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;The macro variable &amp;amp;DatePublication is not a valid SAS date. It is the text string 13/06/2023. SAS does not recognize this as a date, even though humans do recognize this as a date.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Some humans might.&amp;nbsp; My calendar only has 12 months in a year so 13/06/2023 does not look like a date to me.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2023 15:50:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-date-with-macro-date/m-p/880455#M347882</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-13T15:50:42Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the date with macro date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-date-with-macro-date/m-p/880459#M347884</link>
      <description>&lt;P&gt;When working with macro variables make sure the generate valid code.&amp;nbsp; If I run these two statements:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let DatePublication = %sysfunc(today(), ddmmyy10.);
%put &amp;amp;DatePublication.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I see 13/06/2023 printed in the SAS log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does this look like valid SAS code?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if datepart(d_fin) &amp;gt; 13/06/2023&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You are dividing 13 by 6 and then again by 2023.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To convert 13/06/2023 back into a date you would need to use the INPUT() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if datepart(d_fin) &amp;gt; input("&amp;amp;DatePublication.",ddmmyy10.)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Jun 2023 15:56:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-date-with-macro-date/m-p/880459#M347884</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-13T15:56:25Z</dc:date>
    </item>
  </channel>
</rss>

