<?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: creating end date variable inside sas macro using intnx in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/301642#M270406</link>
    <description>Thanks Ballard.&lt;BR /&gt;&lt;BR /&gt;Here is the error log for the above code that I tried.&lt;BR /&gt;&lt;BR /&gt;4168 %let get_date= 201512;&lt;BR /&gt;4169 %let date = %sysfunc(inputn(&amp;amp;get_date,yymmn6.));&lt;BR /&gt;SYMBOLGEN: Macro variable GET_DATE resolves to 201512&lt;BR /&gt;4170 %put &amp;amp;date;&lt;BR /&gt;SYMBOLGEN: Macro variable DATE resolves to 20423&lt;BR /&gt;20423&lt;BR /&gt;4171 %let end_date=%sysfunc(intnx('month',&amp;amp;date, 0, 'end'));&lt;BR /&gt;SYMBOLGEN: Macro variable DATE resolves to 20423&lt;BR /&gt;WARNING: An argument to the function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function&lt;BR /&gt;is out of range.&lt;BR /&gt;NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The&lt;BR /&gt;result of the operations have been set to a missing value.&lt;BR /&gt;</description>
    <pubDate>Thu, 29 Sep 2016 21:21:56 GMT</pubDate>
    <dc:creator>vsharipriya</dc:creator>
    <dc:date>2016-09-29T21:21:56Z</dc:date>
    <item>
      <title>creating end date variable inside sas macro using intnx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/301625#M270401</link>
      <description>&lt;P&gt;I extracted month and year from a string and would like to create a end date of the month, store it in a macro variable. I tried &lt;A href="https://communities.sas.com/t5/SAS-Procedures/using-macro-variables-for-INTNX-function/td-p/31589?nobounce" target="_self"&gt;this example&lt;/A&gt;. This doesnt work in the following program.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Options mprint symbolgen;
%macro mac_name(name);

  %let get_month = %substr(&amp;amp;get_date,5,2); /* get_Date is in the form of yyyymm , ex: 201512) */
  %let get_year = %substr(&amp;amp;get_Date,1,4);
 %let date=  %input(catt(&amp;amp;get_year, &amp;amp;get_month), yymmn6.) ;
/* I want to get the end date of the month */
 %let end_date=%sysfunc(intnx('month',&amp;amp;date, 0, 'end'),yymmdd10.);

%do; 
 		data x;
                set y;
where mem_date= &amp;amp;end_date;
run;
%end;

%mend mac_name;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Sep 2016 20:03:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/301625#M270401</guid>
      <dc:creator>vsharipriya</dc:creator>
      <dc:date>2016-09-29T20:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: creating end date variable inside sas macro using intnx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/301628#M270402</link>
      <description>&lt;P&gt;While this can be debugged, you are making life very difficult by trying to do the processing in macro language.&amp;nbsp; Since you already have &amp;amp;GET_DATE, why not use it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data x;&lt;/P&gt;
&lt;P&gt;set y;&lt;/P&gt;
&lt;P&gt;where mem_date + 1 = intnx('month', input("&amp;amp;get_date.01", yymmdd8.), +1);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2016 20:16:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/301628#M270402</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-09-29T20:16:24Z</dc:date>
    </item>
    <item>
      <title>Re: creating end date variable inside sas macro using intnx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/301629#M270403</link>
      <description>&lt;P&gt;Please describe how "it doesn't work". If you get error messages include the log with the code submitted and the entire error message. If the error occurs with a macro involved use Options Mprint Symbolgen to get details of how the macro actually executed.&lt;/P&gt;
&lt;P&gt;If you get unexpected results then show the actual result and the desired result.&lt;/P&gt;
&lt;P&gt;If you get no result show the expected result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%INPUT is NOT the same as the Input datastep instruction. When you use %INPUT the macro processor is expecting you to use values entered into a %Window dialogue box.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I must ask why did you disassemble a 6 character string into a 4 and 2 character string just to put them back together again?&lt;/P&gt;
&lt;P&gt;Please examine this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let get_date= 201512;
%let date = %sysfunc(inputn(&amp;amp;get_date,yymmn6.)); 
%put &amp;amp;date;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The is no need for, and would be an error, to include the format in this statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token macroname"&gt;%let&lt;/SPAN&gt; end_date&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token macrostatement"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;intnx&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'month'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;date&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;0&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'end'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;yymmdd10&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;Try&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;&lt;SPAN class="token macroname"&gt;%let&lt;/SPAN&gt; end_date&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token macrostatement"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;intnx&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'month'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;date&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;0&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'end'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2016 20:24:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/301629#M270403</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-09-29T20:24:08Z</dc:date>
    </item>
    <item>
      <title>Re: creating end date variable inside sas macro using intnx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/301632#M270404</link>
      <description>&lt;P&gt;The reason I am creating a macro variable is I am calling this macro by passing several datasets like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
 set sashelp.vmember( where=(libname='X' and memtype='DATA'));
 call execute('%mac_name('||strip(memname)||')');
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;mac_name has the form&amp;nbsp; XYZ_PQR_2015_20151, XYZ_PQR_2015_20152, XYZ_PQR_2015_20153..XYZ_PQR_2015_201512&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I created a macro variable get_Date by extracting the last part of the name , to identify each dataset by its month.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %let get_date = %scan(&amp;amp;tname,4,'_');&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;Hence get_date varies with name, so should the end_Date.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2016 20:33:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/301632#M270404</guid>
      <dc:creator>vsharipriya</dc:creator>
      <dc:date>2016-09-29T20:33:44Z</dc:date>
    </item>
    <item>
      <title>Re: creating end date variable inside sas macro using intnx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/301636#M270405</link>
      <description>&lt;P&gt;Under those conditions, that's even more reason to do your processing in a DATA step.&amp;nbsp; You are already working in a DATA step, and you already have a DATA step variable MEMNAME that contains the key information.&amp;nbsp; Let the same DATA step do the processing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It might be easiest to redefine %MAC_NAME so that it uses a second parameter.&amp;nbsp; Then the same DATA step can calculate the proper cutoff date, and add to the CALL EXECUTE statement to pass that second parameter.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2016 20:46:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/301636#M270405</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-09-29T20:46:16Z</dc:date>
    </item>
    <item>
      <title>Re: creating end date variable inside sas macro using intnx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/301642#M270406</link>
      <description>Thanks Ballard.&lt;BR /&gt;&lt;BR /&gt;Here is the error log for the above code that I tried.&lt;BR /&gt;&lt;BR /&gt;4168 %let get_date= 201512;&lt;BR /&gt;4169 %let date = %sysfunc(inputn(&amp;amp;get_date,yymmn6.));&lt;BR /&gt;SYMBOLGEN: Macro variable GET_DATE resolves to 201512&lt;BR /&gt;4170 %put &amp;amp;date;&lt;BR /&gt;SYMBOLGEN: Macro variable DATE resolves to 20423&lt;BR /&gt;20423&lt;BR /&gt;4171 %let end_date=%sysfunc(intnx('month',&amp;amp;date, 0, 'end'));&lt;BR /&gt;SYMBOLGEN: Macro variable DATE resolves to 20423&lt;BR /&gt;WARNING: An argument to the function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function&lt;BR /&gt;is out of range.&lt;BR /&gt;NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The&lt;BR /&gt;result of the operations have been set to a missing value.&lt;BR /&gt;</description>
      <pubDate>Thu, 29 Sep 2016 21:21:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/301642#M270406</guid>
      <dc:creator>vsharipriya</dc:creator>
      <dc:date>2016-09-29T21:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: creating end date variable inside sas macro using intnx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/301649#M270407</link>
      <description>Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;.&lt;BR /&gt;You meant, process the macro statements for calculating cut off date in the data step before call execute? Then again, my problem is I am not able to generate the date in the required format.&lt;BR /&gt;&lt;BR /&gt;Here, if I pass XYZ_PQR_2015_201512 as name , the end_Date should be 2015-12-31 , if I pass XYZ_PQR_2015_201512 as name, the end _Date should be 2015-01-31 .&lt;BR /&gt;&lt;BR /&gt;Later in the where statement I want to subset records with mem_date equal to this end_Date.&lt;BR /&gt;&lt;BR /&gt;I thought it is easier to do this in a separate macro as each time the macro is executed by call execute, the end_Date changes with respect to the name passed.</description>
      <pubDate>Thu, 29 Sep 2016 21:39:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/301649#M270407</guid>
      <dc:creator>vsharipriya</dc:creator>
      <dc:date>2016-09-29T21:39:29Z</dc:date>
    </item>
    <item>
      <title>Re: creating end date variable inside sas macro using intnx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/301655#M270408</link>
      <description>&lt;P&gt;The macro processor treats everything as text so the quotes aren't needed in this call to intnx&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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; end_date=&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, 0, end));&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;%put&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; &amp;amp;end_date;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt;This kind of debugging is another reason to process such things in a datastep if at all possible.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2016 22:21:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/301655#M270408</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-09-29T22:21:24Z</dc:date>
    </item>
    <item>
      <title>Re: creating end date variable inside sas macro using intnx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/301668#M270409</link>
      <description>&lt;P&gt;Yes, that's the idea. &amp;nbsp;Right now, each CALL EXECUTE generates a statement along these lines:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mac_name(XYZ_PQR_2015_201512)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The idea is to change the definition of %MAC_NAME so that this version would be effective:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mac_name(XYZ_PQR_2015_201512,#####)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this example, ##### represents a SAS date. &amp;nbsp;So you would need to redefine the macro in a way that it accepts two parameters (the name of the incoming file, and the cutoff date). &amp;nbsp;The easiest way to both see that the macro is doing the correct thing and to pass the correct date would be to use DATE9 format:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mac_name(XYZ_PQR_2015_20152,31Dec2015)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can make that value available as a DATA step variable. &amp;nbsp;Prior to CALL EXECUTE, you already have a value for MEMNAME. &amp;nbsp;You could code, for example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;YM = scan(memname, -1, '_');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That gets you the five or six digits at the end, as a character string. &amp;nbsp;Then replace it. &amp;nbsp;There are many ways, but here's one:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;year = input(ym, 4.);&lt;/P&gt;
&lt;P&gt;mon = input( substr(ym, 5), 2.);&lt;/P&gt;
&lt;P&gt;beginning_of_month = mdy(mon, 1, year);&lt;/P&gt;
&lt;P&gt;ym = put( intnx('month', beginning_of_month, 0, 'E'), date9.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't test it right now ... it looks about right although I wouldn't be surprised if somebody came up with a shortcut.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Right now, you are using:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;call execute( '%mac_name(' || strip(memname) || ')' );&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That would become:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;call execute( '%mac_name(' || strip(memname) || ', ' || strip(ym) || ')' );&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you would be calling the macro with two parameters instead of one. &amp;nbsp;You would need to change the macro definition, but all the information is available, ready to pass to the macro because the DATA step can easily calculate the proper values. &amp;nbsp;Inside the macro, you could compare:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where mem_date = "&amp;amp;second_parameter"d;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use whatever the name of the second parameter is, when you rewrite the macro definition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OK, I've rambled long enough ... that's just my approach and you are certainly a lot closer than you were originally with the suggestions you have tried from ballardw.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2016 00:24:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/301668#M270409</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-09-30T00:24:59Z</dc:date>
    </item>
    <item>
      <title>Re: creating end date variable inside sas macro using intnx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/301768#M270410</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt; , for the details.&lt;BR /&gt;&lt;BR /&gt;This approach works too. But when I am trying to subset in the where clause,&lt;BR /&gt;&lt;BR /&gt;where mem_date = "&amp;amp;second_parameter"d;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;It throws an error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR:Invalid date/time/datetime constant '2015-01-31'd&lt;/P&gt;&lt;P&gt;ERROR: Syntax error while parsing WHERE clause&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I am not sure why it cannot resolve 'end_Date'd in the where clause.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw﻿&lt;/a&gt; , any thoughts on this?&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2016 15:28:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/301768#M270410</guid>
      <dc:creator>vsharipriya</dc:creator>
      <dc:date>2016-09-30T15:28:13Z</dc:date>
    </item>
    <item>
      <title>Re: creating end date variable inside sas macro using intnx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/301769#M270411</link>
      <description>Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;, this works.</description>
      <pubDate>Fri, 30 Sep 2016 15:17:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/301769#M270411</guid>
      <dc:creator>vsharipriya</dc:creator>
      <dc:date>2016-09-30T15:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: creating end date variable inside sas macro using intnx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/301801#M270412</link>
      <description>&lt;P&gt;Date constants in SAS must use DATE9 format. &amp;nbsp;This is illegal:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'2015-01-31'd&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is legal:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'31Jan2015'd&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2016 17:09:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/301801#M270412</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-09-30T17:09:20Z</dc:date>
    </item>
    <item>
      <title>Re: creating end date variable inside sas macro using intnx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/302147#M270413</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw﻿&lt;/a&gt;&amp;nbsp;. So, when I pass my end_date as a parameter to my macro , following an approach suggested by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in this statement -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; end_Date &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; execute(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'%mac_name('&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;||strip(memname)||&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;','&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;||end_date||&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;')'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;); &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;I formatted my end_Date as date9. before passing this parameter.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;So in my macro, the where clause still gives the error::Invalid date/time/datetime constant '&amp;amp;end_date'd .&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;In the log, I can see that the end_Date actually resolves to '31JAN2015'&amp;nbsp;, which I believe it is considering as a string.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;Do I need to format the end_Date inside the macro, before the where clause too? If so, how can I format the date inside a data step in my macro?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;Thanks.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2016 19:15:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/302147#M270413</guid>
      <dc:creator>vsharipriya</dc:creator>
      <dc:date>2016-10-03T19:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: creating end date variable inside sas macro using intnx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/302174#M270414</link>
      <description>&lt;P&gt;On the CALL EXECUTE statement, you refer to END_DATE.&amp;nbsp; It is still numeric, although it has a format connected with it.&amp;nbsp; (In fact, if END_DATE were character, you would get an error message for trying to assign a numeric format to a character variable.)&amp;nbsp; To get the CALL EXECUTE statement to include the END_DATE in the DATE9 format, you have to replace ||END_DATE|| with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;||put(end_date, date9.)||&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2016 20:35:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/302174#M270414</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-10-03T20:35:22Z</dc:date>
    </item>
    <item>
      <title>Re: creating end date variable inside sas macro using intnx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/302185#M270415</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;&lt;/P&gt;&lt;P&gt;I tried but still I get the following error:&lt;/P&gt;&lt;P&gt;ERROR: Invalid date/time/datetime constant '&amp;amp;end_date'd.&lt;/P&gt;&lt;P&gt;ERROR: Syntax error while parsing WHERE clause.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
 set sashelp.vmember( where=(libname='X'and memtype='DATA'));
 get_date = scan(memname,4,'_'); 
 get_year = substr(get_date,1,4);
 date= input(get_date,yymmn6.); 
 if get_year="2015" then end_date=(intnx('month',date, 0, 'end'));
 if get_year="2016" then end_date= '31Dec2015'd;
 call execute('%mac_name('||strip(memname)||','||put(end_date, date9.)||')');
 ;
run;

options mprint symbolgen;
%macro mac_name(mac_name,end_date);
%do;
    		data temp;
		set temp;
		where mem_date='&amp;amp;end_date'd;&lt;BR /&gt;		run;
       proc append base=date_test data=temp force;
       run;
 %end;
 %mend mac_name;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2016 14:20:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/302185#M270415</guid>
      <dc:creator>vsharipriya</dc:creator>
      <dc:date>2016-10-04T14:20:30Z</dc:date>
    </item>
    <item>
      <title>Re: creating end date variable inside sas macro using intnx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/302214#M270416</link>
      <description>&lt;P&gt;Within your macro definition, you have to use double quotes around references to macro variables. &amp;nbsp;Single quotes prevent the resolution of macro variables. &amp;nbsp;Switch to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where mem_date = "&amp;amp;end_date"d;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2016 02:05:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/302214#M270416</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-10-04T02:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: creating end date variable inside sas macro using intnx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/302358#M270417</link>
      <description>&lt;P&gt;I tried this and it worked:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%put&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(inputn(&amp;amp;end_date,date9.)); /* before the data step in macro*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;where mem_Date= &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;STRONG&gt;"&amp;amp;end_date."d&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2016 15:00:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-end-date-variable-inside-sas-macro-using-intnx/m-p/302358#M270417</guid>
      <dc:creator>vsharipriya</dc:creator>
      <dc:date>2016-10-04T15:00:49Z</dc:date>
    </item>
  </channel>
</rss>

