<?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: Trying to do mathmatical calculation on macro variable dates in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-do-mathmatical-calculation-on-macro-variable-dates/m-p/518873#M3661</link>
    <description>&lt;P&gt;Try wrapping it in %SYSEVALF().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let end_date_6m = 31JUL2018;
%let datalimit= 04DEC2018;



%if %sysevalf("&amp;amp;end_date_6m."d &amp;lt; "&amp;amp;datalimit."d) %then %do;

	%put ERROR- Testing complete;

%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This worked fine for me:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;338 %let end_date_6m = 31JUL2018;&lt;BR /&gt;339 %let datalimit= 04DEC2018;&lt;BR /&gt;340&lt;BR /&gt;341&lt;BR /&gt;342&lt;BR /&gt;343 %if %sysevalf("&amp;amp;end_date_6m."d &amp;lt; "&amp;amp;datalimit."d) %then %do;&lt;BR /&gt;344&lt;BR /&gt;345 %put ERROR- Testing complete;&lt;BR /&gt; &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Testing complete&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;346&lt;BR /&gt;347 %end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 05 Dec 2018 17:36:41 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-12-05T17:36:41Z</dc:date>
    <item>
      <title>Trying to do mathmatical calculation on macro variable dates</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-do-mathmatical-calculation-on-macro-variable-dates/m-p/518872#M3660</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to write some code that I need to run to backdate some reports. I want to compare data at one point to six months later.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created macro variables in the code like this: -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt; query_month = '01feb2018'd;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt; datalimit = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;(intnx(day,&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;(today()),-1),date9.);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*Create macro variables;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="1"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="1"&gt;_null_&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="1"&gt;month = intnx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;'month'&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;,&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="1"&gt;query_month.&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="1"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="1"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt; symputx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;"file_month"&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;,put(intnx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;'month'&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;,month, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="1"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="1"&gt;), &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="1"&gt;monyy5.&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;),&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;'G'&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt; symputx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;"start_file"&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;,put(intnx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;'month'&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;,month,-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="1"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="1"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;'e'&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;), &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="1"&gt;yymmddn8.&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;),&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;'G'&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt; symputx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;"start_date"&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;,put(intnx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;'month'&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;,month,-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="1"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="1"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;'e'&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;), &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="1"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;),&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;'G'&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt; symputx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;"end_file_1m"&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;,put(intnx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;'month'&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;,month,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="1"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="1"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;'e'&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;), &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="1"&gt;yymmddn8.&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;),&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;'G'&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt; symputx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;"end_date_1m"&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;,put(intnx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;'month'&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;,month,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="1"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="1"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;'e'&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;), &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="1"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;),&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;'G'&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt; symputx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;"end_file_6m"&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;,put(intnx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;'month'&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;,month,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="1"&gt;5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="1"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;'e'&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;), &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="1"&gt;yymmddn8.&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;),&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;'G'&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt; symputx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;"end_date_6m"&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;,put(intnx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;'month'&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;,month,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="1"&gt;5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="1"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;'e'&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;), &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="1"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;),&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="1"&gt;'G'&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="1"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The rest of my program is a macro program. Halfway into it, I then have some code that compares the &amp;amp;end_date_6m date with the &amp;amp;datalimit date and only want the next bit of code to run if the &amp;amp;end_date_6m is prior to &amp;amp;datalimit, as the data will not exist otherwise.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The log shows that the macro variables are being resolved as I would expect but SAS doesn't read one date as being earlier than the other&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;%if&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="1"&gt;"&amp;amp;end_date_6m."d&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="1"&gt; &amp;lt; &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="1"&gt;"&amp;amp;datalimit."d&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="1"&gt;%then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="1"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SYMBOLGEN: Macro variable END_DATE_6M resolves to 31JUL2018&lt;/P&gt;&lt;P&gt;SYMBOLGEN: Macro variable DATALIMIT resolves to 04DEC2018&lt;/P&gt;&lt;P&gt;MLOGIC(ROLL_RATES): %IF condition "&amp;amp;end_date_6m."d &amp;lt; "&amp;amp;datalimit."d is FALSE&lt;/P&gt;&lt;P&gt;MLOGIC(ROLL_RATES): Ending execution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm sure this must be something to do with the macro variables being resolved as character rather then the numeric values but could anyone advise me what I need to do to correct this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As always, many thanks in advance.&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;</description>
      <pubDate>Wed, 05 Dec 2018 17:28:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-do-mathmatical-calculation-on-macro-variable-dates/m-p/518872#M3660</guid>
      <dc:creator>robulon</dc:creator>
      <dc:date>2018-12-05T17:28:07Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to do mathmatical calculation on macro variable dates</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-do-mathmatical-calculation-on-macro-variable-dates/m-p/518873#M3661</link>
      <description>&lt;P&gt;Try wrapping it in %SYSEVALF().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let end_date_6m = 31JUL2018;
%let datalimit= 04DEC2018;



%if %sysevalf("&amp;amp;end_date_6m."d &amp;lt; "&amp;amp;datalimit."d) %then %do;

	%put ERROR- Testing complete;

%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This worked fine for me:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;338 %let end_date_6m = 31JUL2018;&lt;BR /&gt;339 %let datalimit= 04DEC2018;&lt;BR /&gt;340&lt;BR /&gt;341&lt;BR /&gt;342&lt;BR /&gt;343 %if %sysevalf("&amp;amp;end_date_6m."d &amp;lt; "&amp;amp;datalimit."d) %then %do;&lt;BR /&gt;344&lt;BR /&gt;345 %put ERROR- Testing complete;&lt;BR /&gt; &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Testing complete&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;346&lt;BR /&gt;347 %end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Dec 2018 17:36:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-do-mathmatical-calculation-on-macro-variable-dates/m-p/518873#M3661</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-12-05T17:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to do mathmatical calculation on macro variable dates</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-do-mathmatical-calculation-on-macro-variable-dates/m-p/518874#M3662</link>
      <description>&lt;P&gt;Macro variable dates must be actual integers (SAS date values), otherwise the macro processor cannot work with them.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Remove the&amp;nbsp;FORMATting and the PUT function from your CALL SYMPUTX, like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call symputx("end_date_6m",intnx('month',month,5,'e'),'G');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course, the idea of doing mathematical calculations with macro variables, other than integer arithmetic, is not recommended. It's possible, but you have to work harder, as shown by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Dec 2018 17:41:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-do-mathmatical-calculation-on-macro-variable-dates/m-p/518874#M3662</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-12-05T17:41:12Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to do mathmatical calculation on macro variable dates</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-do-mathmatical-calculation-on-macro-variable-dates/m-p/518885#M3667</link>
      <description>&lt;P&gt;Thanks both, you guys are awesome!&lt;/P&gt;</description>
      <pubDate>Wed, 05 Dec 2018 18:14:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-do-mathmatical-calculation-on-macro-variable-dates/m-p/518885#M3667</guid>
      <dc:creator>robulon</dc:creator>
      <dc:date>2018-12-05T18:14:57Z</dc:date>
    </item>
  </channel>
</rss>

