<?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: read multiple txt files automatically in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/read-multiple-txt-files-automatically/m-p/242435#M6300</link>
    <description>One alternative is to use an aggregate file location for you filename.</description>
    <pubDate>Fri, 08 Jan 2016 18:42:33 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2016-01-08T18:42:33Z</dc:date>
    <item>
      <title>read multiple txt files automatically</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/read-multiple-txt-files-automatically/m-p/242433#M6298</link>
      <description>&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;I have a data file as attached. The below is the code to revise the data.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; want;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;infile&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="3"&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'C:\Users\AAB006.txt'&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;lrecl&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;30000&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;x&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;=countw(_infile_);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;do&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; i=&lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;to&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; x;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;Num=scan(_infile_, i, &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;" "&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;end&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;drop&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; i x;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;My next challenge is that: There are thousands of such files in a folder.&amp;nbsp; Is there way that the SAS code can automatically get the files' names, and process each of them automatically, rather than manually do it one by one.&amp;nbsp; Appreciate your help.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2016 18:37:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/read-multiple-txt-files-automatically/m-p/242433#M6298</guid>
      <dc:creator>wutao9999</dc:creator>
      <dc:date>2016-01-08T18:37:30Z</dc:date>
    </item>
    <item>
      <title>Re: read multiple txt files automatically</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/read-multiple-txt-files-automatically/m-p/242435#M6300</link>
      <description>One alternative is to use an aggregate file location for you filename.</description>
      <pubDate>Fri, 08 Jan 2016 18:42:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/read-multiple-txt-files-automatically/m-p/242435#M6300</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-01-08T18:42:33Z</dc:date>
    </item>
    <item>
      <title>Re: read multiple txt files automatically</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/read-multiple-txt-files-automatically/m-p/242439#M6302</link>
      <description>&lt;P&gt;Yes, search on here. The method is typically:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Get list of file names into data set. This can be done via OS commands typically, ie dir on windows and ls on Unix.&lt;/LI&gt;
&lt;LI&gt;Use the filevar option on the infile statement to specify that the input data set will provide variable names.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;If you need one output file per text file you can use the method here.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/General-SAS-Programming/Importing-several-files-into-SAS/m-p/242170#M35014" target="_blank"&gt;https://communities.sas.com/t5/General-SAS-Programming/Importing-several-files-into-SAS/m-p/242170#M35014&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are other solutions listed on the forum as well.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-import-multiple-text-files-that-have/ta-p/223627" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-import-multiple-text-files-that-have/ta-p/223627&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2016 18:53:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/read-multiple-txt-files-automatically/m-p/242439#M6302</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-01-08T18:53:11Z</dc:date>
    </item>
    <item>
      <title>Re: read multiple txt files automatically</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/read-multiple-txt-files-automatically/m-p/242442#M6303</link>
      <description>&lt;P&gt;Use the FILENAME option on the INFILE statement.&lt;/P&gt;
&lt;P&gt;Here is an example that will keep the name and also number the files, the rows and column location within the row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  length filename fn $200 ;
  infile '*.txt' filename=fn eov=eov length=ll column=cc truncover ;
  fileno+1;
  do row=1 by 1 until (eov) ;
    do col=1 by 1 until (cc&amp;gt;ll);
       input num @ ;
       filename=fn ;
       output;
    end;
    input;
   end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Jan 2016 19:07:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/read-multiple-txt-files-automatically/m-p/242442#M6303</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-01-08T19:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: read multiple txt files automatically</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/read-multiple-txt-files-automatically/m-p/242445#M6304</link>
      <description>&lt;P&gt;I really love Tom's answer. So simple, but perfectly match my needs.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2016 19:23:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/read-multiple-txt-files-automatically/m-p/242445#M6304</guid>
      <dc:creator>wutao9999</dc:creator>
      <dc:date>2016-01-08T19:23:05Z</dc:date>
    </item>
  </channel>
</rss>

