<?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: How do I list and import all the .txt files in a libref location? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-list-and-import-all-the-txt-files-in-a-libref-location/m-p/858205#M339084</link>
    <description>&lt;P&gt;Assigning a LIBNAME won't do you any good, as these are not SAS files which the BASE engine will recognize&lt;/P&gt;
&lt;P&gt;Read the filenames into a dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data filenames;
length dref $8 fname $200;
rc = filename(dref,'/sasdata/data/UX/sales');
did = dopen(dref);
if did then do i = 1 to dnum(did);
  fname = dread(did,i);
  if index(fname,'WEEKLY_SALES_') = 1 and scan(fname,-1,'.') = 'txt' then output;
end;
keep fname;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if all files have the same structure, you can read them in one data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all;
length fname filename $200;
infile '/sasdata/data/UX/sales/WEEKLY_SALES_*.txt' filename=fname;
input
  /* insert variables here */
;
filename = fname;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You may need to add code for skipping header lines. The variable filename will contain the name of the file from which an observation originates.&lt;/P&gt;</description>
    <pubDate>Fri, 10 Feb 2023 15:43:00 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-02-10T15:43:00Z</dc:date>
    <item>
      <title>How do I list and import all the .txt files in a libref location?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-list-and-import-all-the-txt-files-in-a-libref-location/m-p/858190#M339079</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;I have a Linux file location where we store our output files for processing. What I want to do is look into that Linux location and list ALL the .txt files in there and read them in as separate SAS datasets. The core files names are the same WEEKLY_SALES_yyyymmdd with the yyyymmdd varying with no patters (sometimes weekly, sometimes daily depending on the needs).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I list all those .txt files and import them into SAS? There could be as many as 150 .txt files in the folder.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After I assign the libref, then what?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;libname sales '/sasdata/data/UX/sales/';&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Paula&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 04:36:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-list-and-import-all-the-txt-files-in-a-libref-location/m-p/858190#M339079</guid>
      <dc:creator>SASGeek</dc:creator>
      <dc:date>2023-02-10T04:36:00Z</dc:date>
    </item>
    <item>
      <title>Re: How do I list and import all the .txt files in a libref location?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-list-and-import-all-the-txt-files-in-a-libref-location/m-p/858205#M339084</link>
      <description>&lt;P&gt;Assigning a LIBNAME won't do you any good, as these are not SAS files which the BASE engine will recognize&lt;/P&gt;
&lt;P&gt;Read the filenames into a dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data filenames;
length dref $8 fname $200;
rc = filename(dref,'/sasdata/data/UX/sales');
did = dopen(dref);
if did then do i = 1 to dnum(did);
  fname = dread(did,i);
  if index(fname,'WEEKLY_SALES_') = 1 and scan(fname,-1,'.') = 'txt' then output;
end;
keep fname;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if all files have the same structure, you can read them in one data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all;
length fname filename $200;
infile '/sasdata/data/UX/sales/WEEKLY_SALES_*.txt' filename=fname;
input
  /* insert variables here */
;
filename = fname;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You may need to add code for skipping header lines. The variable filename will contain the name of the file from which an observation originates.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 15:43:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-list-and-import-all-the-txt-files-in-a-libref-location/m-p/858205#M339084</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-10T15:43:00Z</dc:date>
    </item>
    <item>
      <title>Re: How do I list and import all the .txt files in a libref location?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-list-and-import-all-the-txt-files-in-a-libref-location/m-p/858266#M339104</link>
      <description>Thank you. I was worried that would be the answer but at least I know where to go now.&lt;BR /&gt;</description>
      <pubDate>Fri, 10 Feb 2023 14:48:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-list-and-import-all-the-txt-files-in-a-libref-location/m-p/858266#M339104</guid>
      <dc:creator>SASGeek</dc:creator>
      <dc:date>2023-02-10T14:48:26Z</dc:date>
    </item>
  </channel>
</rss>

