<?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 %If statement using dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-statement-using-dates/m-p/449095#M112985</link>
    <description>&lt;P&gt;Hi there!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm stuck with the following code (simplified version):&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro testing(data);

%IF &amp;amp;data. &amp;lt;= '31MAY2014'd %THEN %DO;
%put 1;
%IF '31MAY2014'd  &amp;lt; &amp;amp;data. &amp;lt;= '31DEC2014'd %THEN %DO;
%put 2;
%IF '31DEC2014'd  &amp;lt; &amp;amp;data. &amp;lt;= '30APR2016'd %THEN %DO;
%put 3;

%mend;

%testing('30JUN2015'd);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Ideally, the code should print a '3' in the log, but it prints a 1.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried with datepart() and different time formats. I need to run different macros depending on the date, but I'm not able to evaluate whether a date is within a range.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could someone help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Mar 2018 18:40:58 GMT</pubDate>
    <dc:creator>nicolasb</dc:creator>
    <dc:date>2018-03-27T18:40:58Z</dc:date>
    <item>
      <title>%If statement using dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-statement-using-dates/m-p/449095#M112985</link>
      <description>&lt;P&gt;Hi there!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm stuck with the following code (simplified version):&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro testing(data);

%IF &amp;amp;data. &amp;lt;= '31MAY2014'd %THEN %DO;
%put 1;
%IF '31MAY2014'd  &amp;lt; &amp;amp;data. &amp;lt;= '31DEC2014'd %THEN %DO;
%put 2;
%IF '31DEC2014'd  &amp;lt; &amp;amp;data. &amp;lt;= '30APR2016'd %THEN %DO;
%put 3;

%mend;

%testing('30JUN2015'd);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Ideally, the code should print a '3' in the log, but it prints a 1.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried with datepart() and different time formats. I need to run different macros depending on the date, but I'm not able to evaluate whether a date is within a range.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could someone help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 18:40:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-statement-using-dates/m-p/449095#M112985</guid>
      <dc:creator>nicolasb</dc:creator>
      <dc:date>2018-03-27T18:40:58Z</dc:date>
    </item>
    <item>
      <title>Re: %If statement using dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-statement-using-dates/m-p/449113#M112994</link>
      <description>&lt;P&gt;You're three steps away from having working code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, macro language doesn't compare dates.&amp;nbsp; At least not by default.&amp;nbsp; It compares character strings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, a series of comparisons doesn't work the same way in macro language as it does in a DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Third, you need an %END statement for each %DO.&amp;nbsp; (Those probably got dropped when simplifying the example.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All of that can be fixed.&amp;nbsp; Here's the sort of statements that would work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if %sysevalf(&amp;amp;data. &amp;lt;= '31MAY2014'd) %then %put 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%else %if %sysevalf('31MAY2014'd &amp;lt; &amp;amp;data) and %sysevalf(&amp;amp;data &amp;lt;= '31DEC2014'd) %then %put 2;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 19:06:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-statement-using-dates/m-p/449113#M112994</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-03-27T19:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: %If statement using dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-statement-using-dates/m-p/449122#M112999</link>
      <description>&lt;P&gt;By default SAS uses the %EVAL() macro function in %IF, %WHILE and %UNTIL clauses.&amp;nbsp; That function can only handle integer comparisons.&amp;nbsp; It does not handle date literals (or floating point arithmetic).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use %SYSEVALF() to evaluate values that use date literals.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also macro code will not convert A&amp;lt;B&amp;lt;C into (A&amp;lt;B) and (B&amp;lt;C) like SAS code will.&amp;nbsp; Instead if will evaluate A&amp;lt;B to either 0 or 1 and then test if that is &amp;lt;C.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 19:19:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-statement-using-dates/m-p/449122#M112999</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-27T19:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: %If statement using dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-statement-using-dates/m-p/449127#M113001</link>
      <description>&lt;P&gt;It worked! Thank you very much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 19:26:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-statement-using-dates/m-p/449127#M113001</guid>
      <dc:creator>nicolasb</dc:creator>
      <dc:date>2018-03-27T19:26:42Z</dc:date>
    </item>
    <item>
      <title>Re: %If statement using dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-statement-using-dates/m-p/449128#M113002</link>
      <description>Thanks a lot!! It worked with the %SYSEVALF()</description>
      <pubDate>Tue, 27 Mar 2018 19:27:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-statement-using-dates/m-p/449128#M113002</guid>
      <dc:creator>nicolasb</dc:creator>
      <dc:date>2018-03-27T19:27:14Z</dc:date>
    </item>
  </channel>
</rss>

