<?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: Fail to use macro to import multiple txt files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Fail-to-use-macro-to-import-multiple-txt-files/m-p/593669#M170410</link>
    <description>Hello, macro variables inside single quoted strings are not resolved.&lt;BR /&gt;Try&lt;BR /&gt;infile "D:files\price_&amp;amp;ym..txt" dsd dlm='09'x truncover;&lt;BR /&gt;instead.</description>
    <pubDate>Thu, 03 Oct 2019 11:12:03 GMT</pubDate>
    <dc:creator>gamotte</dc:creator>
    <dc:date>2019-10-03T11:12:03Z</dc:date>
    <item>
      <title>Fail to use macro to import multiple txt files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fail-to-use-macro-to-import-multiple-txt-files/m-p/593663#M170406</link>
      <description>&lt;P&gt;Hello guys, I write a sas macro to import multiple txt files as follows, however, it fails no matter how I improve it.&lt;/P&gt;&lt;P&gt;The log says the physical files don't exist.&lt;/P&gt;&lt;P&gt;Can anyone help me?&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro all_on_index(syear=, eyear=);

%do year = &amp;amp;syear %to &amp;amp;eyear;
	%do month = 1 %to 12;
	%let ym = %eval(&amp;amp;year*100 + &amp;amp;month);

data work.op;
 infile 'D:files\price_&amp;amp;ym..txt' dsd dlm='09'x truncover;
 input var1:$20.     var2:YYMMDD8.;

%if year = &amp;amp;syear and month = 1 %then %do;
	data work._all;
		set work.op;
	run;
	%end;
%else %do;
	data work._all;
		set work._all work.op;
	run;
	%end;

	%end;
%end;

%mend all_options_on_index;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I will appreciate it very much for your help!!&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 10:29:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fail-to-use-macro-to-import-multiple-txt-files/m-p/593663#M170406</guid>
      <dc:creator>xizidememeda</dc:creator>
      <dc:date>2019-10-03T10:29:51Z</dc:date>
    </item>
    <item>
      <title>Re: Fail to use macro to import multiple txt files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fail-to-use-macro-to-import-multiple-txt-files/m-p/593668#M170409</link>
      <description>&lt;P&gt;I marked the issues:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro all_on_index(syear=, eyear=);
%local year month ym; /* make your macro behave if it's called from another macro that uses the same variables */
%do year = &amp;amp;syear %to &amp;amp;eyear;
  %do month = 1 %to 12;
    %let ym = %eval(&amp;amp;year*100 + &amp;amp;month);

data work.op;
infile "D:files\price_&amp;amp;ym..txt" dsd dlm='09'x truncover; /* use double quotes to resolve macro variables */
input var1:$20. var2:YYMMDD8.;
run; /* always a good idea to define clear step boundaries */

    %if &amp;amp;year = &amp;amp;syear and month = 1 %then %do; /* "year" is just a string, use &amp;amp;year for the macro variable */

data work._all;
set work.op;
run;

    %end;
    %else %do;

data work._all;
set work._all work.op;
run;

    %end;
  %end;
%end;

%mend all_options_on_index;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can simplify the code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro all_on_index(syear=, eyear=);
%local year month ym;
%do year = &amp;amp;syear %to &amp;amp;eyear;
  %do month = 1 %to 12;
    %let ym = %eval(&amp;amp;year*100 + &amp;amp;month);

data work.op;
infile "D:files\price_&amp;amp;ym..txt" dsd dlm='09'x truncover;
input var1:$20. var2:YYMMDD8.;
run;

data work._all;
set
%if &amp;amp;year ne &amp;amp;syear or &amp;amp;month ne 1 %then work._all;
  work.op
;
run;

  %end;
%end;

%mend all_options_on_index;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 11:13:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fail-to-use-macro-to-import-multiple-txt-files/m-p/593668#M170409</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-03T11:13:45Z</dc:date>
    </item>
    <item>
      <title>Re: Fail to use macro to import multiple txt files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fail-to-use-macro-to-import-multiple-txt-files/m-p/593669#M170410</link>
      <description>Hello, macro variables inside single quoted strings are not resolved.&lt;BR /&gt;Try&lt;BR /&gt;infile "D:files\price_&amp;amp;ym..txt" dsd dlm='09'x truncover;&lt;BR /&gt;instead.</description>
      <pubDate>Thu, 03 Oct 2019 11:12:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fail-to-use-macro-to-import-multiple-txt-files/m-p/593669#M170410</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-10-03T11:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: Fail to use macro to import multiple txt files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fail-to-use-macro-to-import-multiple-txt-files/m-p/593674#M170413</link>
      <description>&lt;P&gt;I rewrite my complete codes based on your reply and comments and it works very well!&lt;/P&gt;&lt;P&gt;Thanks very much for your help!!&lt;img id="smileylol" class="emoticon emoticon-smileylol" src="https://communities.sas.com/i/smilies/16x16_smiley-lol.png" alt="Smiley LOL" title="Smiley LOL" /&gt;&lt;img id="heart" class="emoticon emoticon-heart" src="https://communities.sas.com/i/smilies/16x16_heart.png" alt="Heart" title="Heart" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 11:32:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fail-to-use-macro-to-import-multiple-txt-files/m-p/593674#M170413</guid>
      <dc:creator>xizidememeda</dc:creator>
      <dc:date>2019-10-03T11:32:59Z</dc:date>
    </item>
    <item>
      <title>Re: Fail to use macro to import multiple txt files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fail-to-use-macro-to-import-multiple-txt-files/m-p/593676#M170415</link>
      <description>&lt;P&gt;Yes, you are right! Many many thanks for your help!&lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://communities.sas.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 11:34:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fail-to-use-macro-to-import-multiple-txt-files/m-p/593676#M170415</guid>
      <dc:creator>xizidememeda</dc:creator>
      <dc:date>2019-10-03T11:34:23Z</dc:date>
    </item>
    <item>
      <title>Re: Fail to use macro to import multiple txt files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fail-to-use-macro-to-import-multiple-txt-files/m-p/593772#M170477</link>
      <description>Since all your files are the same you don't need to use a macro, you can use a wildcard and read them all in one step. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 03 Oct 2019 15:15:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fail-to-use-macro-to-import-multiple-txt-files/m-p/593772#M170477</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-03T15:15:51Z</dc:date>
    </item>
  </channel>
</rss>

