<?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: Intnx function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297426#M62451</link>
    <description>&lt;P&gt;You need to remove the quotes around MONTH and E when calling INTNX within %SYSFUNC() macro function. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;String literals are not quoted in macro code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Sep 2016 15:37:12 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2016-09-09T15:37:12Z</dc:date>
    <item>
      <title>Intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297397#M62433</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I am trying to define three different dates shown as below for the current month (August), previous month (July) and previous two months (June) in the macro statments. It seems worked. However, when I put all of them in the where statement inside the data step&amp;nbsp;below, I got the syntax error. Can anyone advise on this? Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Syntax error while parsing WHERE clause.&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: a numeric constant, a datetime constant, a missing value, ), -.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%LET&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; DATE = '31AUG2016'D;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%LET&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; DATE1 = INTNX('MONTH',&amp;amp;DATE,-1,'E'); &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/* JULY */&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%LET&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; DATE2 = INTNX('MONTH',&amp;amp;DATE,-2,'E'); &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/*JUNE*/&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;　　&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; TEST;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;SET&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; WAREHOUSE;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;WHERE&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; AS_OF_DATE IN (&amp;amp;DATE, &amp;amp;DATE1, &amp;amp;DATE2);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 13:49:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297397#M62433</guid>
      <dc:creator>LL5</dc:creator>
      <dc:date>2016-09-09T13:49:18Z</dc:date>
    </item>
    <item>
      <title>Re: Intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297404#M62439</link>
      <description>&lt;P&gt;Your macro variables are TEXT.&lt;/P&gt;
&lt;P&gt;So when you use&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%LET&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; DATE1 = INTNX('MONTH',&amp;amp;DATE,-1,'E'); &lt;/FONT&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/* JULY */&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%LET&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; DATE2 = INTNX('MONTH',&amp;amp;DATE,-2,'E'); &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/*JUNE*/&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;your Where clause looks like this:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt;WHERE AS_OF_DATE IN (&lt;/FONT&gt;&lt;FONT color="#008080" face="SAS Monospace" size="2"&gt;'31AUG2016'D&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;, INTNX(&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;'MONTH'&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;,&amp;amp;DATE,-&lt;/FONT&gt;&lt;FONT color="#008080" face="SAS Monospace" size="2"&gt;1&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;'E'&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;), INTNX(&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;'MONTH'&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;,&amp;amp;DATE,-&lt;/FONT&gt;&lt;FONT color="#008080" face="SAS Monospace" size="2"&gt;1&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;'E'&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt;For this purpose you want:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0080" face="SAS Monospace" size="2"&gt;%LET&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt; DATE1 = &lt;/FONT&gt;&lt;FONT color="#ff0080" face="SAS Monospace" size="2"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;(INTNX('MONTH',&amp;amp;DATE,-1,'E')); &lt;/FONT&gt;&lt;FONT color="#075f03" face="SAS Monospace" size="2"&gt;/* JULY */&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0080" face="SAS Monospace" size="2"&gt;&lt;FONT color="#ff0080" face="SAS Monospace" size="2"&gt;&lt;FONT color="#ff0080" face="SAS Monospace" size="2"&gt;%LET&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;&lt;FONT face="SAS Monospace" size="2"&gt; DATE2 = &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#ff0080" face="SAS Monospace" size="2"&gt;&lt;FONT color="#ff0080" face="SAS Monospace" size="2"&gt;&lt;FONT color="#ff0080" face="SAS Monospace" size="2"&gt;%sysfunc&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;&lt;FONT face="SAS Monospace" size="2"&gt;(INTNX('MONTH',&amp;amp;DATE,-2,'E')); &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#075f03" face="SAS Monospace" size="2"&gt;&lt;FONT color="#075f03" face="SAS Monospace" size="2"&gt;&lt;FONT color="#075f03" face="SAS Monospace" size="2"&gt;/*JUNE*/&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#075f03" face="SAS Monospace" size="2"&gt;to RESOLVE the value of the function INTNX. The %sysfunc is used to resolve data step functions in macros code or values.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 14:30:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297404#M62439</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-09-09T14:30:20Z</dc:date>
    </item>
    <item>
      <title>Re: Intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297407#M62441</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks Ballardw. I added the &lt;FONT color="#ff0080" face="SAS Monospace" size="2"&gt;%sysfunc &lt;/FONT&gt;but i still didn't get July and June data. I got the warning message as below:&lt;/P&gt;&lt;P&gt;Do you have any ideas? Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LET DATE = '31AUG2016'D;&lt;/P&gt;&lt;P&gt;16 %LET DATE1 = %sysfunc(INTNX('MONTH',&amp;amp;DATE,-1,'E'));&lt;/P&gt;&lt;P&gt;WARNING: An argument to the function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.&lt;/P&gt;&lt;P&gt;NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The result of the operations have been set&lt;/P&gt;&lt;P&gt;to a missing value.&lt;/P&gt;&lt;P&gt;17&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 14:45:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297407#M62441</guid>
      <dc:creator>LL5</dc:creator>
      <dc:date>2016-09-09T14:45:26Z</dc:date>
    </item>
    <item>
      <title>Re: Intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297424#M62450</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%LET&lt;FONT face="Courier New" size="3"&gt; DATE = '31AUG2016'D;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%LET&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; DATE1 = INTNX('MONTH',&amp;amp;DATE,-1,'E'); &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008000"&gt;&lt;FONT face="Courier New" size="3" color="#008000"&gt;&lt;FONT face="Courier New" size="3" color="#008000"&gt;/* JULY */&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%LET&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; DATE2 = INTNX('MONTH',&amp;amp;DATE,-2,'E'); &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008000"&gt;&lt;FONT face="Courier New" size="3" color="#008000"&gt;&lt;FONT face="Courier New" size="3" color="#008000"&gt;/*JUNE*/&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;　　&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; TEST;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;SET&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; WAREHOUSE;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;WHERE&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; AS_OF_DATE IN (&amp;amp;DATE, &amp;amp;DATE1, &amp;amp;DATE2);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is strictly a matter of personal coding style, but the style I've developed over the years is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) I don't embed "syntax" in my macro variables. &amp;nbsp;I want my macro variables to only contain data.&lt;/P&gt;&lt;P&gt;2) For macro variables containing date, time, or datetime, I prefer stroring them as date/time/datetime literals. &amp;nbsp;It often makes the log look better, such as the echoing of the where clause in the data step above.&lt;/P&gt;&lt;P&gt;3) Even with SQL Server passthrough, where date literals must be single-quoted, I use either:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; A) WHERE DATE BETWEEN %bquote('&amp;amp;startdate') and %bquote('&amp;amp;enddate'); &amp;nbsp;or&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; B) %let q=%str(%'); &amp;nbsp;WHERE DATE BETWEEN &amp;amp;q&amp;amp;startdate&amp;amp;q and &amp;amp;q&amp;amp;enddate&amp;amp;q;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used to use B), then a colleague put me onto the %bquote() macro function. &amp;nbsp;Now I think A looks better, even with the extra keystrokes - I just think it looks clearer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, this then becomes:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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 DATE  = 31AUG2016;&lt;BR /&gt;* or even %LET DATE = %sysfunc(INTNX(MONTH,"12AUG2016"d,0,E),date9.);  * to ensure the EOM ;
%LET DATE1 = %sysfunc(INTNX(MONTH,"&amp;amp;DATE"d,-1,E),date9.); /* JULY */
%LET DATE2 = %sysfunc(INTNX(MONTH,"&amp;amp;DATE"d,-2,E),date9.); /*JUNE*/

%PUT &amp;amp;=DATE &amp;amp;=DATE1 &amp;amp;=DATE2; &amp;nbsp;* for debugging ;
　　
DATA TEST;
SET WAREHOUSE;
WHERE AS_OF_DATE IN ("&amp;amp;DATE"d, "&amp;amp;DATE1"d, "&amp;amp;DATE2"d);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Run that and see how the log looks cleaner, with the date literals displayed in the where clause, instead of some number which represents the date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;See the doc for the %sysfunc function and the use of the optional &amp;lt;format&amp;gt; to format the output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;HTH...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 16:14:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297424#M62450</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2016-09-09T16:14:37Z</dc:date>
    </item>
    <item>
      <title>Re: Intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297426#M62451</link>
      <description>&lt;P&gt;You need to remove the quotes around MONTH and E when calling INTNX within %SYSFUNC() macro function. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;String literals are not quoted in macro code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 15:37:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297426#M62451</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-09-09T15:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: Intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297431#M62455</link>
      <description>&lt;P&gt;Since you're trying to process the data with DATA step functions, it might be easier to read if you used a DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let date = '31aug2016'd;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;call symputx('date1', intnx('month', &amp;amp;date, -1, 'E'));&lt;/P&gt;
&lt;P&gt;call symputx('date2', intnx('month', &amp;amp;date, -2, 'E'));&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then the SQL code can remain as is.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 15:45:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297431#M62455</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-09-09T15:45:04Z</dc:date>
    </item>
    <item>
      <title>Re: Intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297434#M62457</link>
      <description>&lt;P&gt;Do not add quotes around string literals in macro code. &amp;nbsp;The INTNX() function is complaining that is doesn't know anything about a time interval named 'MONTH'. It is looking for MONTH or YEAR or DAY etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET DATE = '31AUG2016'D;
%LET DATE_number = %sysfunc(INTNX(MONTH,&amp;amp;DATE,-1,E));
%LET DATE_string = %sysfunc(INTNX(MONTH,&amp;amp;DATE,-1,E),DATE9);
%LET DATE_literal = "%sysfunc(INTNX(MONTH,&amp;amp;DATE,-1,E),DATE9)"D;

%put &amp;amp;=date_number ;
%put &amp;amp;=date_string ;
%put &amp;amp;=date_literal ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use the values of &amp;amp;DATE_NUMBER or &amp;amp;DATE_LITERAL inter changably in your code. &amp;nbsp;But if you want to use &amp;amp;DATE_STRING to mean a date then you need to use it in the format "&amp;amp;DATE_STRING"D to convert it to a date literal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 15:46:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297434#M62457</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-09-09T15:46:36Z</dc:date>
    </item>
    <item>
      <title>Re: Intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297443#M62464</link>
      <description>&lt;P&gt;&amp;amp;date1 would then be something like 12345 and &amp;amp;date2 something like 12372, or whatever number of days after 01JAN1960 represent those dates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you %put those values to the log, it would be difficult to know if you'd generated the correct result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you used those values in a where clause, the SAS notes would use those values, rather than the date literals, again making it difficult to know if you've selected the correct records.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's just personal preference...I just prefer the literals.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, even if you use a data step, this then becomes:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
call symputx('date1', put(intnx('month', &amp;amp;date, -1, 'E'),date9.);
call symputx('date2', put(intnx('month', &amp;amp;date, -2, 'E'),date9.);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I personally don't find this easier to read than the use of %sysfunc, but that's just a matter of coding style. &amp;nbsp;Both approaches work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(Kudos for using symputx - as far as I'm concerned symput is deprecated!)&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 16:40:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297443#M62464</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2016-09-09T16:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: Intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297449#M62466</link>
      <description>&lt;P&gt;Guilty as charged, but this is mostly a matter of style ... I might use your suggestion for QC of a program, but I would rely on the program to work if the right numbers were in there. &amp;nbsp;Depending on what the program does, it might be apparent (from the reports it produces) whether the right dates were being selected.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that if you do convert the DATA step as you suggested (and assuming you balance the parentheses), you have to change the SQL code. &amp;nbsp;You can no longer refer to &amp;amp;DATE1 (and similarly &amp;amp;DATE2), but have to switch to "&amp;amp;DATE1"d.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 16:36:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297449#M62466</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-09-09T16:36:19Z</dc:date>
    </item>
    <item>
      <title>Re: Intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297471#M62468</link>
      <description>&lt;P&gt;Thanks everybody here! The codes below worked perfectly now!&lt;/P&gt;&lt;P&gt;Now I am trying to automate date5 and date6, which would be the March end of the previous two years(as always).&lt;/P&gt;&lt;P&gt;I wonder if there's any way to automate it?&lt;/P&gt;&lt;P&gt;Really being gladly apperciated for everyone's helps here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%LET&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; DATE = '31AUG2016'D;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%LET&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; DATE1 = &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;(INTNX(MONTH,&amp;amp;DATE,-1,E));&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%LET&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; DATE2 = &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;(INTNX(QTR,&amp;amp;DATE,-1,E));&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%LET&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; DATE3 = &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;(INTNX(QTR,&amp;amp;DATE,-2,E));&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%LET&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; DATE4 = &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;(INTNX(MONTH,&amp;amp;DATE,-12,E));&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%LET&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; DATE5 = '31MAR2015'D;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%LET&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; DATE6 = '31MAR2014'D;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; TEST;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;SET&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; WAREHOUSE;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;WHERE&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; AS_OF_DATE IN (&amp;amp;DATE, &amp;amp;DATE1,&amp;amp;DATE2, &amp;amp;DATE3, &amp;amp;DATE4, &amp;amp;DATE5, &amp;amp;DATE6)&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 18:41:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297471#M62468</guid>
      <dc:creator>LL5</dc:creator>
      <dc:date>2016-09-09T18:41:25Z</dc:date>
    </item>
    <item>
      <title>Re: Intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297477#M62469</link>
      <description>&lt;P&gt;Is DATE5 always going to be March of the year prior to Date1? or the fifth month prior to date1 and then the previous year?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You already know how to get Date6 from Date5, use intnx with Year instead of Month.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 19:47:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297477#M62469</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-09-09T19:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: Intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297494#M62476</link>
      <description>Date5 is always the March of the year prior to date1, where date6 is always the March of two years prior to date1.</description>
      <pubDate>Fri, 09 Sep 2016 21:29:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297494#M62476</guid>
      <dc:creator>LL5</dc:creator>
      <dc:date>2016-09-09T21:29:27Z</dc:date>
    </item>
    <item>
      <title>Re: Intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297499#M62478</link>
      <description>&lt;P&gt;You really want to move this stuff to a data step and create the macro variables with call symputx. You have to nest so many function calls, each of which calling for an explicit %sysfunc or calculation calling for an %eval or %sysevalf that the code gets ugly and hard to maintain.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
   DATE1 = '31AUG2016'D;
   date5 = mdy(3,31,Year(date)-1);
   date6 = intnx('Year',date5,-1,'S');
   format date date5 date6 date9.;
   /* call symputx statements left as an exercise for
      the interested reader*/
run;

%let date1 = '31AUG2016'D;
%let date5 = %sysfunc(mdy(3,31,%eval(%sysfunc(year(&amp;amp;date1)) -1))) ;
%let date6 = %sysfunc(intnx(YEAR,&amp;amp;date5,-1,S));
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Sep 2016 21:53:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297499#M62478</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-09-09T21:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: Intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297502#M62481</link>
      <description>&lt;P&gt;One of the nice features of %SYSFUNC() is that you don't need to add %EVAL() for the function arguments.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can call %sysfunc(mdy(3,31,2015-1)) the same way you can call mdy(3,31,2015-1) in a&amp;nbsp;normal SAS code.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 21:58:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297502#M62481</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-09-09T21:58:14Z</dc:date>
    </item>
    <item>
      <title>Re: Intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297506#M62485</link>
      <description>Thanks everyone so much for all the advices!! I tried the below approach and it worked.&lt;BR /&gt;%LET YEAR = 2016;&lt;BR /&gt;%LET DATE = '31AUG2016'D;&lt;BR /&gt;%LET DATE1 = %sysfunc(INTNX(MONTH,&amp;amp;DATE,-1,E));&lt;BR /&gt;%LET DATE2 = %sysfunc(INTNX(QTR,&amp;amp;DATE,-1,E));&lt;BR /&gt;%LET DATE3 = %sysfunc(INTNX(QTR,&amp;amp;DATE,-2,E));&lt;BR /&gt;%LET DATE4 = %sysfunc(INTNX(MONTH,&amp;amp;DATE,-12,E));&lt;BR /&gt;%LET DATE5 = %sysfunc(MDY(3,31,&amp;amp;YEAR-1));&lt;BR /&gt;%LET DATE6 = %sysfunc(INTNX(MONTH,&amp;amp;DATE5,-12,E));&lt;BR /&gt;&lt;BR /&gt;DATA TEST;&lt;BR /&gt;SET WAREHOUSE;&lt;BR /&gt;WHERE AS_OF_DATE IN (&amp;amp;DATE, &amp;amp;DATE1,&amp;amp;DATE2, &amp;amp;DATE3, &amp;amp;DATE4, &amp;amp;DATE5, &amp;amp;DATE6);&lt;BR /&gt;RUN;</description>
      <pubDate>Fri, 09 Sep 2016 22:30:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297506#M62485</guid>
      <dc:creator>LL5</dc:creator>
      <dc:date>2016-09-09T22:30:31Z</dc:date>
    </item>
    <item>
      <title>Re: Intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297507#M62486</link>
      <description>And also, I used this in Proc Sql, it worked as well.</description>
      <pubDate>Fri, 09 Sep 2016 22:32:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297507#M62486</guid>
      <dc:creator>LL5</dc:creator>
      <dc:date>2016-09-09T22:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: Intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297596#M62525</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/89004"&gt;@LL5&lt;/a&gt; wrote:&lt;BR /&gt;Thanks everyone so much for all the advices!! I tried the below approach and it worked.&lt;BR /&gt;%LET YEAR = 2016;&lt;BR /&gt;%LET DATE = '31AUG2016'D;&lt;BR /&gt;%LET DATE1 = %sysfunc(INTNX(MONTH,&amp;amp;DATE,-1,E));&lt;BR /&gt;%LET DATE2 = %sysfunc(INTNX(QTR,&amp;amp;DATE,-1,E));&lt;BR /&gt;%LET DATE3 = %sysfunc(INTNX(QTR,&amp;amp;DATE,-2,E));&lt;BR /&gt;%LET DATE4 = %sysfunc(INTNX(MONTH,&amp;amp;DATE,-12,E));&lt;BR /&gt;%LET DATE5 = %sysfunc(MDY(3,31,&amp;amp;YEAR-1));&lt;BR /&gt;%LET DATE6 = %sysfunc(INTNX(MONTH,&amp;amp;DATE5,-12,E));&lt;BR /&gt;&lt;BR /&gt;DATA TEST;&lt;BR /&gt;SET WAREHOUSE;&lt;BR /&gt;WHERE AS_OF_DATE IN (&amp;amp;DATE, &amp;amp;DATE1,&amp;amp;DATE2, &amp;amp;DATE3, &amp;amp;DATE4, &amp;amp;DATE5, &amp;amp;DATE6);&lt;BR /&gt;RUN;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As often with SAS (and Perl), "there is more than one way to do it" (tm)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now that this has evolved to six macro variables (and perhaps more in the future?), perhaps a non-macro approach could be useful?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The "real" problem here is selecting records matching key dates. &amp;nbsp;The macro code was just to derive those dates. &amp;nbsp;This can be done in many ways without the use of macro:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First create your desired dates (however you choose to do so):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dates;
   start='31AUG2016'd;  * or today(), or whatever seed value you need ;
   date=intnx('month',start,0,'E');output;
   date=intnx('qtr',start,-2,'E');output;
   date=mdy(31,3,2016-1);output;
   date=mdy(1,4,2016-2)-1;output;
   * etc, etc, ;  * create a dataset containing the dates you want ;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Then, you can subset your data with:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;* merge and IN= &amp;nbsp;(but this requires the source and lookup data to be sorted)&lt;/P&gt;&lt;P&gt;* proc sql inner join (but this will sort the source data under the covers)&lt;/P&gt;&lt;P&gt;* proc sql nested query &amp;nbsp;(proc sql; create table test as select * from warehouse where date in (select date from dates) )&lt;/P&gt;&lt;P&gt;* create a format from your dates, then: &amp;nbsp;(data test; set warehouse; if not missing(put(date,mydatefmt.)); run; )&lt;/P&gt;&lt;P&gt;* use a hash object for your dates, and check the return code from the hash.lookup() function&lt;/P&gt;&lt;P&gt;* create an indexed dataset for your dates, and use a lookup ("double set statement"), and check _iorc_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;None of these approaches would use macro, and might be easier to modify if your needs change in the future.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If your WAREHOUSE dataset is large you want to avoid sorting. &amp;nbsp;Use the _method option on proc sql to see if it sorted your source table or not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps...&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2016 09:19:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297596#M62525</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2016-09-12T09:19:11Z</dc:date>
    </item>
    <item>
      <title>Re: Intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297748#M62558</link>
      <description>&lt;P&gt;Thanks ScottBass for letting me know the other approaches to accomplish this. Since the data in warehouse is very large which contains lots of observations and variables, I used Proc Sql followed by lots of Proc Tabulate statements to get the end result. I will keep in mind for all the different approaches that you mentioned above and may come up with additional questions in the future. Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2016 13:35:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intnx-function/m-p/297748#M62558</guid>
      <dc:creator>LL5</dc:creator>
      <dc:date>2016-09-12T13:35:33Z</dc:date>
    </item>
  </channel>
</rss>

