<?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 Macro variables in Macro variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-variables-in-Macro-variables/m-p/379101#M91217</link>
    <description>&lt;P&gt;Hi - I'm trying to&amp;nbsp;automate something&amp;nbsp;in SAS, but I'm very rusty.&amp;nbsp; I want to create a macro variable that reflects the current months date that I can use to identify a dataset in a proc sql later on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've already set up a macro variable which gives me the first of the current month in a date format - I'll call this &amp;amp;currentmonth I want to use this data to identify a dataset that we'll call libname.accounts201707.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I create a variable like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let currfile = year(&amp;amp;currmonth)||month(currmonth);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;which should resolve to 201707, yes?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But when I create the proc sql:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table example as&lt;/P&gt;&lt;P&gt;select&amp;nbsp; field1,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;field2&lt;/P&gt;&lt;P&gt;from&amp;nbsp;&amp;nbsp; libname.accounts&amp;amp;currfile;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it doesn't work as it's looking for:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;libname.accountsyear(&amp;amp;currmonth)||month(currmonth)&lt;/P&gt;&lt;P&gt;rather than&lt;/P&gt;&lt;P&gt;libname.accounts201707&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I feel like I'm so close to cracking this but it's getting the better of me...?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help?&lt;/P&gt;</description>
    <pubDate>Tue, 25 Jul 2017 16:06:24 GMT</pubDate>
    <dc:creator>Stan76</dc:creator>
    <dc:date>2017-07-25T16:06:24Z</dc:date>
    <item>
      <title>Macro variables in Macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variables-in-Macro-variables/m-p/379101#M91217</link>
      <description>&lt;P&gt;Hi - I'm trying to&amp;nbsp;automate something&amp;nbsp;in SAS, but I'm very rusty.&amp;nbsp; I want to create a macro variable that reflects the current months date that I can use to identify a dataset in a proc sql later on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've already set up a macro variable which gives me the first of the current month in a date format - I'll call this &amp;amp;currentmonth I want to use this data to identify a dataset that we'll call libname.accounts201707.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I create a variable like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let currfile = year(&amp;amp;currmonth)||month(currmonth);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;which should resolve to 201707, yes?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But when I create the proc sql:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table example as&lt;/P&gt;&lt;P&gt;select&amp;nbsp; field1,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;field2&lt;/P&gt;&lt;P&gt;from&amp;nbsp;&amp;nbsp; libname.accounts&amp;amp;currfile;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it doesn't work as it's looking for:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;libname.accountsyear(&amp;amp;currmonth)||month(currmonth)&lt;/P&gt;&lt;P&gt;rather than&lt;/P&gt;&lt;P&gt;libname.accounts201707&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I feel like I'm so close to cracking this but it's getting the better of me...?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help?&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2017 16:06:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variables-in-Macro-variables/m-p/379101#M91217</guid>
      <dc:creator>Stan76</dc:creator>
      <dc:date>2017-07-25T16:06:24Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variables in Macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variables-in-Macro-variables/m-p/379103#M91218</link>
      <description>&lt;P&gt;%SYSFUNC() -&amp;gt; need this to use functions in macro to differentiate between text and code. There' s a fairly simple solution though, using a format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let current_month = %sysfunc(today(), yymmn6.);
%put &amp;amp;current_month;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/155709"&gt;@Stan76&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi - I'm trying to&amp;nbsp;automate something&amp;nbsp;in SAS, but I'm very rusty.&amp;nbsp; I want to create a macro variable that reflects the current months date that I can use to identify a dataset in a proc sql later on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've already set up a macro variable which gives me the first of the current month in a date format - I'll call this &amp;amp;currentmonth I want to use this data to identify a dataset that we'll call libname.accounts201707.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I create a variable like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let currfile = year(&amp;amp;currmonth)||month(currmonth);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;which should resolve to 201707, yes?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But when I create the proc sql:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;create table example as&lt;/P&gt;
&lt;P&gt;select&amp;nbsp; field1,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;field2&lt;/P&gt;
&lt;P&gt;from&amp;nbsp;&amp;nbsp; libname.accounts&amp;amp;currfile;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it doesn't work as it's looking for:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;libname.accountsyear(&amp;amp;currmonth)||month(currmonth)&lt;/P&gt;
&lt;P&gt;rather than&lt;/P&gt;
&lt;P&gt;libname.accounts201707&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I feel like I'm so close to cracking this but it's getting the better of me...?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2017 16:11:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variables-in-Macro-variables/m-p/379103#M91218</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-25T16:11:03Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variables in Macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variables-in-Macro-variables/m-p/379106#M91219</link>
      <description>&lt;P&gt;Could you please let us know the error or warning you are getting with the one you tried&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2017 16:12:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variables-in-Macro-variables/m-p/379106#M91219</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2017-07-25T16:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variables in Macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variables-in-Macro-variables/m-p/379192#M91247</link>
      <description>&lt;P&gt;Since you do not show what your value for &amp;amp;currmonth actually is (hint: %put &amp;amp;currmonth; ) then it is hard to say. There are so many ways that people play with dates I'm not going to assume anything about your specific values without an example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is working through an example and shows why you likely have at least 2 errors in your currfile value:&lt;/P&gt;
&lt;PRE&gt;%let year = %sysfunc( year( %sysfunc( today() ) ) );
%put Year is &amp;amp;year;
%let month = %sysfunc( month( %sysfunc( today() ) ) );
%put Month is &amp;amp;month ;  /* NOTE there is no leading 0*/

%let month = %sysfunc(putn (%sysfunc( month( %sysfunc( today() ) ) ),Z2.));
%put Month is &amp;amp;month ; 


%let currfile = &amp;amp;year||&amp;amp;month;
%put Currfile is &amp;amp;currfile;
/* correct concatenation of two macro variables*/
%let currfile = &amp;amp;year.&amp;amp;month;
%put Currfile is &amp;amp;currfile;


/* Or */
data _null_;
   currfile= cats(year(today()),put(month(today()),z2.));
   call symputx ('currfile',currfile);
run;

%put &amp;amp;currfile;
&lt;/PRE&gt;
&lt;P&gt;Sometimes it is easer to use data step functions in a data step and create a macro variable than to manipulate in macro language.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2017 19:54:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variables-in-Macro-variables/m-p/379192#M91247</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-07-25T19:54:49Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variables in Macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variables-in-Macro-variables/m-p/379281#M91285</link>
      <description>&lt;P&gt;&lt;SPAN class="token macroname"&gt;I tried this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token macroname"&gt;%let&lt;/SPAN&gt; current_month &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;today&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; yymmn6&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;BR /&gt;&lt;SPAN class="token macrostatement"&gt;%put&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;current_month&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token punctuation"&gt;and it works fine, however when I replace today() with &amp;amp;currmonth. I get the following error:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;476 %let current_month = %sysfunc(&amp;amp;currmonth., yymmn6.);&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800000"&gt;ERROR: Function name missing in %SYSFUNC or %QSYSFUNC macro function reference.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(fyi - &amp;amp;currmonth = '01jun2017'd)&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2017 07:23:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variables-in-Macro-variables/m-p/379281#M91285</guid>
      <dc:creator>Stan76</dc:creator>
      <dc:date>2017-07-26T07:23:07Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variables in Macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variables-in-Macro-variables/m-p/379282#M91286</link>
      <description>&lt;P&gt;Solved with the call symput - thank you everyone!&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2017 07:26:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variables-in-Macro-variables/m-p/379282#M91286</guid>
      <dc:creator>Stan76</dc:creator>
      <dc:date>2017-07-26T07:26:03Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variables in Macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variables-in-Macro-variables/m-p/379352#M91307</link>
      <description>&lt;P&gt;Here's a paper that discusses handling dates in the macro language.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.sascommunity.org/wiki/Macro_Loops_with_Dates" target="_blank"&gt;http://www.sascommunity.org/wiki/Macro_Loops_with_Dates&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ron Fehd&amp;nbsp; date info maven&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2017 12:11:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variables-in-Macro-variables/m-p/379352#M91307</guid>
      <dc:creator>Ron_MacroMaven</dc:creator>
      <dc:date>2017-07-26T12:11:50Z</dc:date>
    </item>
  </channel>
</rss>

