<?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 Trouble comparing date macros in a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Trouble-comparing-date-macros-in-a-macro/m-p/788711#M252240</link>
    <description>&lt;P&gt;I can't figure out what I'm doing wrong:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro test();&lt;/P&gt;&lt;P&gt;%if "06DEC2021"d&amp;lt;"05JAN2022"d&lt;BR /&gt;%then %do;&lt;BR /&gt;%put "Lesser";&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;%put "Why doesn't it work?";&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;%test();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How are you supposed to compare dates?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Thu, 06 Jan 2022 17:59:59 GMT</pubDate>
    <dc:creator>python_user</dc:creator>
    <dc:date>2022-01-06T17:59:59Z</dc:date>
    <item>
      <title>Trouble comparing date macros in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trouble-comparing-date-macros-in-a-macro/m-p/788711#M252240</link>
      <description>&lt;P&gt;I can't figure out what I'm doing wrong:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro test();&lt;/P&gt;&lt;P&gt;%if "06DEC2021"d&amp;lt;"05JAN2022"d&lt;BR /&gt;%then %do;&lt;BR /&gt;%put "Lesser";&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;%put "Why doesn't it work?";&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;%test();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How are you supposed to compare dates?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 17:59:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trouble-comparing-date-macros-in-a-macro/m-p/788711#M252240</guid>
      <dc:creator>python_user</dc:creator>
      <dc:date>2022-01-06T17:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble comparing date macros in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trouble-comparing-date-macros-in-a-macro/m-p/788712#M252241</link>
      <description>&lt;P&gt;The macro processor does not recognize dates as dates, it recognizes them as text strings. And text strings sort alphabetically, so 05JAN2022 is less than (alphabetically) 06DEC2021.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To compare dates, use either a SAS data step, or convert the dates to SAS date values which are integers which can then be compared by the SAS macro processor effectively.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
     length value $ 7;
     if '06DEC2021'd &amp;lt; '05JAN2022'd then value='Lesser';
     else value='Greater';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let abc=%sysevalf("05JAN2022"d);
%let def=%sysevalf("06DEC2021"d);
%if &amp;amp;abc&amp;lt;&amp;amp;def %then %do; %put LESSER; %end;
%else %do; %put GREATER; %end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Jan 2022 18:12:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trouble-comparing-date-macros-in-a-macro/m-p/788712#M252241</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-06T18:12:54Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble comparing date macros in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trouble-comparing-date-macros-in-a-macro/m-p/788716#M252245</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks, I guess it explains&amp;nbsp;&lt;EM&gt;why&amp;nbsp;&lt;/EM&gt;it's not working. Unfortunately for me the sysevalf also does not work (output is GREATER):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro test();&lt;BR /&gt;%let abc=%sysevalf("05JAN2022"d);&lt;BR /&gt;%let def=%sysevalf("06DEC2021"d);&lt;BR /&gt;%if &amp;amp;abc&amp;lt;&amp;amp;def %then %do; %put LESSER; %end;&lt;BR /&gt;%else %do; %put GREATER; %end;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;%test();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;any other ideas on how to compare dates in a macro?&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 18:19:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trouble-comparing-date-macros-in-a-macro/m-p/788716#M252245</guid>
      <dc:creator>python_user</dc:creator>
      <dc:date>2022-01-06T18:19:34Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble comparing date macros in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trouble-comparing-date-macros-in-a-macro/m-p/788717#M252246</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/328313"&gt;@python_user&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;GREATER is the correct answer, at least on my calendar.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 18:22:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trouble-comparing-date-macros-in-a-macro/m-p/788717#M252246</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-06T18:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble comparing date macros in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trouble-comparing-date-macros-in-a-macro/m-p/788718#M252247</link>
      <description>&lt;P&gt;Ha! So it is. Apologies and thanks again.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 18:29:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trouble-comparing-date-macros-in-a-macro/m-p/788718#M252247</guid>
      <dc:creator>python_user</dc:creator>
      <dc:date>2022-01-06T18:29:35Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble comparing date macros in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trouble-comparing-date-macros-in-a-macro/m-p/788719#M252248</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/328313"&gt;@python_user&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks, I guess it explains&amp;nbsp;&lt;EM&gt;why&amp;nbsp;&lt;/EM&gt;it's not working. Unfortunately for me the sysevalf also does not work (output is GREATER):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro test();&lt;BR /&gt;%let abc=%sysevalf("05JAN2022"d);&lt;BR /&gt;%let def=%sysevalf("06DEC2021"d);&lt;BR /&gt;%if &amp;amp;abc&amp;lt;&amp;amp;def %then %do; %put LESSER; %end;&lt;BR /&gt;%else %do; %put GREATER; %end;&lt;BR /&gt;%mend;&lt;/P&gt;
&lt;P&gt;%test();&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;any other ideas on how to compare dates in a macro?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Look back at the direction of the comparison and your values. "05JAN2022"d is greater than (after) "06DEC2021"d .&lt;/P&gt;
&lt;P&gt;Run the macro with options Symbolgen and MLOGIC&lt;/P&gt;
&lt;PRE&gt;options  symbolgen mlogic;
%test();
options  nosymbolgen nomlogic;&lt;/PRE&gt;
&lt;PRE&gt;123  options  symbolgen mlogic;
124  %test();
MLOGIC(TEST):  Beginning execution.
MLOGIC(TEST):  %LET (variable name is ABC)
MLOGIC(TEST):  %LET (variable name is DEF)
SYMBOLGEN:  Macro variable ABC resolves to &lt;FONT color="#FF00FF"&gt;&lt;STRONG&gt;22650&lt;/STRONG&gt;&lt;/FONT&gt;
SYMBOLGEN:  Macro variable DEF resolves to &lt;FONT color="#FF00FF"&gt;&lt;STRONG&gt;22620&lt;/STRONG&gt;&lt;/FONT&gt;
MLOGIC(TEST):  %IF condition &amp;amp;abc&amp;lt;&amp;amp;def is FALSE
MLOGIC(TEST):  %PUT GREATER
GREATER
MLOGIC(TEST):  Ending execution.
125  options  nosymbolgen nomlogic;
&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Jan 2022 18:31:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trouble-comparing-date-macros-in-a-macro/m-p/788719#M252248</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-01-06T18:31:09Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble comparing date macros in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trouble-comparing-date-macros-in-a-macro/m-p/788727#M252253</link>
      <description>&lt;P&gt;Yes, good point&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Actually looking at the values of your macro variables is always an excellent debugging strategy, and I'm surprised when people don't do that.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 19:21:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trouble-comparing-date-macros-in-a-macro/m-p/788727#M252253</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-06T19:21:19Z</dc:date>
    </item>
  </channel>
</rss>

