<?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 Detect files and create one append table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Detect-files-and-create-one-append-table/m-p/375752#M90124</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I have a directory &amp;amp;dir, with several files in txt in it. Some files begin by "FILE_" others don't.&lt;BR /&gt;The files beginning by "FILE_" have the same format, "hopefully"&lt;BR /&gt;A $6&lt;BR /&gt;B $12&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just need to create a table Z, as an append of all files beginning by "FILE_" whatever is the number of files in the directory dir.&lt;/P&gt;&lt;P&gt;I am a bit lost on how to do that.&lt;BR /&gt;Can someone help me on 'easy' problem (I am a SAS almost beginner)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Thu, 13 Jul 2017 16:36:53 GMT</pubDate>
    <dc:creator>FP12</dc:creator>
    <dc:date>2017-07-13T16:36:53Z</dc:date>
    <item>
      <title>Detect files and create one append table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Detect-files-and-create-one-append-table/m-p/375752#M90124</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I have a directory &amp;amp;dir, with several files in txt in it. Some files begin by "FILE_" others don't.&lt;BR /&gt;The files beginning by "FILE_" have the same format, "hopefully"&lt;BR /&gt;A $6&lt;BR /&gt;B $12&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just need to create a table Z, as an append of all files beginning by "FILE_" whatever is the number of files in the directory dir.&lt;/P&gt;&lt;P&gt;I am a bit lost on how to do that.&lt;BR /&gt;Can someone help me on 'easy' problem (I am a SAS almost beginner)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2017 16:36:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Detect-files-and-create-one-append-table/m-p/375752#M90124</guid>
      <dc:creator>FP12</dc:creator>
      <dc:date>2017-07-13T16:36:53Z</dc:date>
    </item>
    <item>
      <title>Re: Detect files and create one append table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Detect-files-and-create-one-append-table/m-p/375785#M90136</link>
      <description>&lt;P&gt;You could use sas functions to&amp;nbsp;open a directory and get a list of file names in that directory, but this problem is also amenable to using an operating system command to trivially list the desired files names.&amp;nbsp; That list can be put in an %include file, as in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename mypipe pipe "dir/b c:\temp\FILE_*.txt";
filename tmp  temp ;

data _null_;
  infile mypipe truncover end=eod;
  input filnam $50.;
  filnam=cats('c:\temp\',filnam);

  file tmp;
  if _n_=1 then put 'infile "(' @;
  else          put ',' @ ;
  put filnam @;
  if eod then put ')";';
run;

options source2;
data want;
  %include tmp ;
  *input x y;
  input (a b) ($6. $12.);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notes:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;This program assumes a windows environment (hence the use of the "dir/b" command -- i.e. a "bare" directory list of all txt files that have names beginning with "FILE_".&lt;/LI&gt;
&lt;LI&gt;That dir command is embedded within a filename statement of type "pipe" - i.e. pipe the output of the dir command when the filename reference MYPIPE is used.&lt;/LI&gt;
&lt;LI&gt;The "filename tmp temp" established a temporary external file - i.e. it will be deleted when the sas session is finished.&amp;nbsp; You don't need to know where the file is located.&amp;nbsp; You're just going to write stuff to it, and read it back when needed during the session.&lt;/LI&gt;
&lt;LI&gt;The first data step reads in the piped list of file names, prepends&amp;nbsp;the directory name and writes an INFILE statement with&amp;nbsp;a comma-separated list of full names to TMP.&amp;nbsp; The result will look like this:&lt;BR /&gt;&amp;nbsp;&amp;nbsp; infile "(c:\temp\FILE_001.txt ,c:\temp\FILE_002.txt)" ;&lt;/LI&gt;
&lt;LI&gt;The second data step uses "%include tmp" to read in&amp;nbsp;TMP as one or more SAS statements.&amp;nbsp; Note the "option source2" which tells sas to print to log the content of the %include files .&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Thu, 13 Jul 2017 18:09:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Detect-files-and-create-one-append-table/m-p/375785#M90136</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-07-13T18:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: Detect files and create one append table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Detect-files-and-create-one-append-table/m-p/376579#M90405</link>
      <description>&lt;P&gt;Hello mkeintz,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got an issue when I try to "include tmp":&lt;/P&gt;&lt;PRE&gt;ERROR: Physical file does not exist, /apps/sas94/sasconfig/Lev1/SASMain/c:\temp/usr/bin/ksh:.&lt;/PRE&gt;&lt;P&gt;I am indeed working on Windows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think it means the file filenam wasn't created as planned in the first datastep?&lt;/P&gt;&lt;P&gt;I don't really understand the path file because you are mixing a SAS path with a Windows path. Is it normal?&lt;/P&gt;&lt;P&gt;Or maybe I am not granted to write (I see a Lev1 in the path that's why I think this)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2017 14:46:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Detect-files-and-create-one-append-table/m-p/376579#M90405</guid>
      <dc:creator>FP12</dc:creator>
      <dc:date>2017-07-17T14:46:40Z</dc:date>
    </item>
  </channel>
</rss>

