<?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: macro for multiple text files, how to assign filename to each file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-for-multiple-text-files-how-to-assign-filename-to-each/m-p/396908#M95883</link>
    <description>I coded it as a macro, because I'm used to working with larger and more varied file layouts that have to be combined. Obviously, I was overthinking - I've never seen this approach - but it worked like a charm! Thank you!</description>
    <pubDate>Mon, 18 Sep 2017 18:39:15 GMT</pubDate>
    <dc:creator>MillerEL</dc:creator>
    <dc:date>2017-09-18T18:39:15Z</dc:date>
    <item>
      <title>macro for multiple text files, how to assign filename to each file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-for-multiple-text-files-how-to-assign-filename-to-each/m-p/396902#M95879</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using a macro to read in 12 txt files. Each file corresponds to a month, but there is no variable within the file that reflects the month - this information is only in the filename. I need help figuring out how to extract the month from the file name within the macro. Each file is named tan&amp;lt;mon&amp;gt;yy. I haven't been able to apply any of the methods I've seen for extracting file names to my code below. Any ideas on how to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename tanf1 'Q:/txtfiles/tan*13.txt' lrecl=80 recfm=v;

%macro tanfin;
	input @1 relind $char1. @3 casdcn $char8. @12 indvdcn $char8.
  		 @21 county $char3. @25 zip $char5. @31 rac $char1. @33 sx 
                 $char1. @35 agen 3. @39 nmon 4. @46 edu $char2.;
%mend tanfin;

DATA one;
	infile tanf1;
	%tanfin;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Sep 2017 18:20:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-for-multiple-text-files-how-to-assign-filename-to-each/m-p/396902#M95879</guid>
      <dc:creator>MillerEL</dc:creator>
      <dc:date>2017-09-18T18:20:39Z</dc:date>
    </item>
    <item>
      <title>Re: macro for multiple text files, how to assign filename to each file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-for-multiple-text-files-how-to-assign-filename-to-each/m-p/396906#M95881</link>
      <description>&lt;P&gt;Not sure why you have coded that input statement as a macro.&lt;/P&gt;
&lt;P&gt;Use the FILENAME= option on the INFILE statement to have SAS tell you want file the current record came from.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename tanf1 'Q:/txtfiles/tan*13.txt' lrecl=80 recfm=v;

data all;
  length fname $256 filename $32 ;
  infile tanf1 filename=fname truncover;
  input @1 relind $char1. @3 casdcn $char8. @12 indvdcn $char8.
        @21 county $char3. @25 zip $char5. @31 rac $char1. 
        @33 sx $char1. @35 agen 3. @39 nmon 4. @46 edu $char2.
  ;
  filename = scan(fname,-2,'./\');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Sep 2017 18:31:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-for-multiple-text-files-how-to-assign-filename-to-each/m-p/396906#M95881</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-18T18:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: macro for multiple text files, how to assign filename to each file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-for-multiple-text-files-how-to-assign-filename-to-each/m-p/396908#M95883</link>
      <description>I coded it as a macro, because I'm used to working with larger and more varied file layouts that have to be combined. Obviously, I was overthinking - I've never seen this approach - but it worked like a charm! Thank you!</description>
      <pubDate>Mon, 18 Sep 2017 18:39:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-for-multiple-text-files-how-to-assign-filename-to-each/m-p/396908#M95883</guid>
      <dc:creator>MillerEL</dc:creator>
      <dc:date>2017-09-18T18:39:15Z</dc:date>
    </item>
  </channel>
</rss>

