<?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 a dynamic macro variable for Month and Year to add to a filename in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-dynamic-macro-variable-for-Month-and-Year-to-add-to-a/m-p/275771#M55197</link>
    <description>&lt;P&gt;It's the right idea, but I would suggest you consider:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let year_month=;&lt;/P&gt;
&lt;P&gt;%if %length(&amp;amp;year_month)=0 %then %let year_month=&amp;nbsp; /* same thing */;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That way, if you ever want to backdate the report, you only need to change the first %LET statement, not the second.&amp;nbsp; But under normal circumstances, just let it run.&lt;/P&gt;</description>
    <pubDate>Tue, 07 Jun 2016 18:13:04 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-06-07T18:13:04Z</dc:date>
    <item>
      <title>Creating a dynamic macro variable for Month and Year to add to a filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-dynamic-macro-variable-for-Month-and-Year-to-add-to-a/m-p/275759#M55192</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm sure this is a relatively easy question (or there is an alternative way of doing it that's less confusing) but I'm working on automating a number of reports I need to run every month.&amp;nbsp; For the first report, all I need to do is export the data from a SQL Server view to a tab delimited file.&amp;nbsp; All that is easy; what I'm stuck on is naming of the file.&amp;nbsp; I'm using SAS 9.4 locally installed on a Windows 7 machine.&lt;/P&gt;
&lt;P&gt;Right now, I have&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mnth = 5;
%let yr = 2016;

proc sql;
create table work.test as
/* a bunch of code */
quit;

proc export data = work.test
      outfile = "C:\Report__&amp;amp;yr&amp;amp;mnth..txt"
      DBMS = tab replace;
      putnames = no;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This all works perfectly, but what I'm trying to do set it up so the &amp;amp;mnth and &amp;amp;yr variables are always the previous month (and year) so I don't have to change them every month.&amp;nbsp; I've tried &amp;nbsp;&amp;amp;month = intnx('month',have.date,-1) but then my file name has the intnx function in the file name, which doesn't help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've spent some time on Lexjansen.com but can't seem to find anything; maybe I'm looking under the wrong keywords (dynamic, fiscal year, export etc.).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any suggestions?&lt;/P&gt;
&lt;P&gt;Thanks!&lt;BR /&gt;Chris&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2016 17:51:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-dynamic-macro-variable-for-Month-and-Year-to-add-to-a/m-p/275759#M55192</guid>
      <dc:creator>DarthPathos</dc:creator>
      <dc:date>2016-06-07T17:51:14Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a dynamic macro variable for Month and Year to add to a filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-dynamic-macro-variable-for-Month-and-Year-to-add-to-a/m-p/275761#M55193</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let year_month = %sysfunc(intnx(month, %sysfunc(today()), -1, b), yymmn6.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Edit: Original answer had two typo's (syfunc vs sysfunc and the b does not need quotation marks).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2016 18:00:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-dynamic-macro-variable-for-Month-and-Year-to-add-to-a/m-p/275761#M55193</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-07T18:00:25Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a dynamic macro variable for Month and Year to add to a filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-dynamic-macro-variable-for-Month-and-Year-to-add-to-a/m-p/275771#M55197</link>
      <description>&lt;P&gt;It's the right idea, but I would suggest you consider:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let year_month=;&lt;/P&gt;
&lt;P&gt;%if %length(&amp;amp;year_month)=0 %then %let year_month=&amp;nbsp; /* same thing */;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That way, if you ever want to backdate the report, you only need to change the first %LET statement, not the second.&amp;nbsp; But under normal circumstances, just let it run.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2016 18:13:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-dynamic-macro-variable-for-Month-and-Year-to-add-to-a/m-p/275771#M55197</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-06-07T18:13:04Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a dynamic macro variable for Month and Year to add to a filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-dynamic-macro-variable-for-Month-and-Year-to-add-to-a/m-p/275775#M55199</link>
      <description>Here I was thinking you were just testing me - I got both but it took some research &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks so much!  Works perfectly (now that I understand what it's doing LOL)</description>
      <pubDate>Tue, 07 Jun 2016 18:22:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-dynamic-macro-variable-for-Month-and-Year-to-add-to-a/m-p/275775#M55199</guid>
      <dc:creator>DarthPathos</dc:creator>
      <dc:date>2016-06-07T18:22:36Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a dynamic macro variable for Month and Year to add to a filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-dynamic-macro-variable-for-Month-and-Year-to-add-to-a/m-p/275776#M55200</link>
      <description>Ooh that's a cool trick - and one I will definitely need for another project.  For this report however I'd never need to backdate - I need to report to the Provincial Government by a set date, and if I miss the deadline, we're screwed O_o.  Having said that, thanks for the reply!!&lt;BR /&gt;Chris</description>
      <pubDate>Tue, 07 Jun 2016 18:24:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-dynamic-macro-variable-for-Month-and-Year-to-add-to-a/m-p/275776#M55200</guid>
      <dc:creator>DarthPathos</dc:creator>
      <dc:date>2016-06-07T18:24:33Z</dc:date>
    </item>
  </channel>
</rss>

