<?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 value in file name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-value-in-file-name/m-p/419746#M103231</link>
    <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;So I want to import both file 201711 and 201710.&lt;/P&gt;
&lt;P&gt;I use the macro &amp;amp;month=11.&lt;/P&gt;
&lt;P&gt;I want to do something like &amp;amp;year.&amp;amp;month-1 to make it 201710.&lt;/P&gt;
&lt;P&gt;Can you help me with it?&lt;/P&gt;
&lt;P&gt;(clearly, I can create a new macro variable, %let &amp;amp;month_1=10)&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let year=2017;
%let month=11;
data rate ;
infile "&amp;amp;path\Rate for &amp;amp;year.&amp;amp;month..csv"
dlm=','  dsd truncover firstobs=2;
input ....&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 09 Dec 2017 00:22:28 GMT</pubDate>
    <dc:creator>hhchenfx</dc:creator>
    <dc:date>2017-12-09T00:22:28Z</dc:date>
    <item>
      <title>Macro value in file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-value-in-file-name/m-p/419746#M103231</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;So I want to import both file 201711 and 201710.&lt;/P&gt;
&lt;P&gt;I use the macro &amp;amp;month=11.&lt;/P&gt;
&lt;P&gt;I want to do something like &amp;amp;year.&amp;amp;month-1 to make it 201710.&lt;/P&gt;
&lt;P&gt;Can you help me with it?&lt;/P&gt;
&lt;P&gt;(clearly, I can create a new macro variable, %let &amp;amp;month_1=10)&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let year=2017;
%let month=11;
data rate ;
infile "&amp;amp;path\Rate for &amp;amp;year.&amp;amp;month..csv"
dlm=','  dsd truncover firstobs=2;
input ....&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Dec 2017 00:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-value-in-file-name/m-p/419746#M103231</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2017-12-09T00:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: Macro value in file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-value-in-file-name/m-p/419747#M103232</link>
      <description>&lt;P&gt;You can use the %EVAL() macro function to do integer arithmetic.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let year=2017;
%let month=11;
%let previous=%eval(&amp;amp;month-1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But what do you do when month=01?&lt;/P&gt;
&lt;P&gt;Use the INTNX() function instead.&amp;nbsp; First convert YEAR and MONTH into an actual date value. Then you can calculate the previous month.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let year=2017;
%let month=11;
%let this_month=%sysfunc(mdy(&amp;amp;month,1,&amp;amp;year));
%let previous_month=%sysfunc(intnx(month,&amp;amp;this_month,-1));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can then use the YYMMN6. format to convert it into the string you need for your filename.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;"&amp;amp;path\Rate for %sysfunc(putn(&amp;amp;previous_month,yymmn6)).csv"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Dec 2017 00:35:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-value-in-file-name/m-p/419747#M103232</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-12-09T00:35:49Z</dc:date>
    </item>
    <item>
      <title>Re: Macro value in file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-value-in-file-name/m-p/419749#M103233</link>
      <description>&lt;P&gt;Oh Tom,&lt;/P&gt;
&lt;P&gt;You are right, I haven't thought bout Jan &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Thanks a lot.&lt;/P&gt;
&lt;P&gt;HC&lt;/P&gt;</description>
      <pubDate>Sat, 09 Dec 2017 00:44:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-value-in-file-name/m-p/419749#M103233</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2017-12-09T00:44:08Z</dc:date>
    </item>
  </channel>
</rss>

