<?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 in multiple excel/text  files in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Read-in-multiple-excel-text-files/m-p/15249#M2648</link>
    <description>Suggestion to OP Norman21 - considering it's your first post, suggesting you want to create new posts on the forums when you have a question/problem/discussion item, instead of piggy-backing on another individual's prior post - if you want to reference a prior post, then past a link to it in your "new" post.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
    <pubDate>Fri, 05 Feb 2010 14:03:47 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2010-02-05T14:03:47Z</dc:date>
    <item>
      <title>Read in multiple excel/text  files</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Read-in-multiple-excel-text-files/m-p/15244#M2643</link>
      <description>I have 300 excel files with file names "Summary File - xxx.xls". xxx can be any of city names, like Cary, etc. However, I am not sure all the city names in the file exactly. I need to read in all the city names from the filenames first, then read all the records into a sas data set. Any one knows how to do this? Thanks.</description>
      <pubDate>Fri, 03 Apr 2009 14:35:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Read-in-multiple-excel-text-files/m-p/15244#M2643</guid>
      <dc:creator>flyingsohigh</dc:creator>
      <dc:date>2009-04-03T14:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: Read in multiple excel/text  files</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Read-in-multiple-excel-text-files/m-p/15245#M2644</link>
      <description>Hello.&lt;BR /&gt;
&lt;BR /&gt;
Using the appropriate SAS functions (it will work on any system):&lt;BR /&gt;
&lt;BR /&gt;
data FILENAME_LIST;&lt;BR /&gt;
   length FILENAME $200;&lt;BR /&gt;
   drop _:; /* drop temporary variables */&lt;BR /&gt;
   _RC=filename('dirref',"D:\Temp"); /* assign dir ref */&lt;BR /&gt;
   _DID=dopen('dirref'); /* open dir */&lt;BR /&gt;
   _NUM_OF_FILES=dnum(_DID); /* get total number of members */&lt;BR /&gt;
   do _I=1 to _NUM_OF_FILES; /* cycle through members /*&lt;BR /&gt;
      FILENAME=dread(_DID,_I); /* read member name */&lt;BR /&gt;
      output;&lt;BR /&gt;
   end;&lt;BR /&gt;
   _RC=dclose(_DID);&lt;BR /&gt;
   _RC=filename('dirref');&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
FILENAME_LIST will contain a row per file in the specified directory.&lt;BR /&gt;
&lt;BR /&gt;
Another way could be piping the result of a list command (system dependent) into a dataset.&lt;BR /&gt;
&lt;BR /&gt;
Something like that (Windows example based on dir command):&lt;BR /&gt;
&lt;BR /&gt;
filename FILELIST pipe "dir /b";&lt;BR /&gt;
&lt;BR /&gt;
data FILENAME_LIST;&lt;BR /&gt;
length FILENAME $200;&lt;BR /&gt;
infile FILELIST;&lt;BR /&gt;
input;&lt;BR /&gt;
FILENAME=_infile_;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
From here you just have to select the desired filenames (say with a approriate wildcard), assign those to macro variables and use the latest on your SAS script.&lt;BR /&gt;
&lt;BR /&gt;
Greetings from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos at &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Daniel Santos</description>
      <pubDate>Fri, 03 Apr 2009 15:05:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Read-in-multiple-excel-text-files/m-p/15245#M2644</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-04-03T15:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: Read in multiple excel/text  files</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Read-in-multiple-excel-text-files/m-p/15246#M2645</link>
      <description>The pipe function works beautifully. Thanks for your suggestion.</description>
      <pubDate>Fri, 03 Apr 2009 19:33:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Read-in-multiple-excel-text-files/m-p/15246#M2645</guid>
      <dc:creator>flyingsohigh</dc:creator>
      <dc:date>2009-04-03T19:33:53Z</dc:date>
    </item>
    <item>
      <title>Re: Read in multiple excel/text  files</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Read-in-multiple-excel-text-files/m-p/15247#M2646</link>
      <description>Hi, I have a similar problem, and this is my first post - so please bear with me!&lt;BR /&gt;
&lt;BR /&gt;
I have an application that writes data to identically-named (and formatted) Excel files in various subdirectories.  I'd like to read the data from each, and merge the whole lot into one large file for subsequent analysis.&lt;BR /&gt;
&lt;BR /&gt;
The files are named as follows (simplified):&lt;BR /&gt;
&lt;BR /&gt;
n:\data\data01\excelfile.xls&lt;BR /&gt;
n:\data\data02\excelfile.xls&lt;BR /&gt;
n:\data\data03\excelfile.xls&lt;BR /&gt;
... (more than 200)&lt;BR /&gt;
&lt;BR /&gt;
I've put all the filenames into a separate text file, then taken a tip from Cody's book as follows:&lt;BR /&gt;
&lt;BR /&gt;
data readmany;&lt;BR /&gt;
infile 'C:\My SAS Files\filelist.txt';&lt;BR /&gt;
input externalnames $ 80.;&lt;BR /&gt;
infile dummy filevar=externalnames end=last;&lt;BR /&gt;
do until (last);&lt;BR /&gt;
input...?;&lt;BR /&gt;
output;&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
proc contents data=readmany;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
I'm not sure what to put after the input statement to make this work.  Also, is there another way to tackle this problem?  I'll get new Excel files from time to time, so will need to re-build the master file periodically.&lt;BR /&gt;
&lt;BR /&gt;
I hope that's clear!&lt;BR /&gt;
&lt;BR /&gt;
Oh, I should add I'm running SAS 9.2 in Windows XP Pro.</description>
      <pubDate>Thu, 04 Feb 2010 20:10:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Read-in-multiple-excel-text-files/m-p/15247#M2646</guid>
      <dc:creator>Norman21</dc:creator>
      <dc:date>2010-02-04T20:10:11Z</dc:date>
    </item>
    <item>
      <title>Re: Read in multiple excel/text  files</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Read-in-multiple-excel-text-files/m-p/15248#M2647</link>
      <description>Hello Norman.&lt;BR /&gt;
&lt;BR /&gt;
From there its actually dependent on the way you are importing the data.&lt;BR /&gt;
&lt;BR /&gt;
I suppose those are standard excel files, and that you have proc import licensed and that you are using it to import the desired files.&lt;BR /&gt;
&lt;BR /&gt;
If so, you'll need to issue a proc import for each file.&lt;BR /&gt;
&lt;BR /&gt;
I think a possible way to code this, would be to load the file list into a list of macro variables...&lt;BR /&gt;
[pre]&lt;BR /&gt;
%let FILELISTN=0; * init file list count;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
infile 'C:\My SAS Files\filelist.txt';&lt;BR /&gt;
input EXTERNALNAMES $ 80.;&lt;BR /&gt;
* create macro variable FILELISTX with the corresponding filename;&lt;BR /&gt;
call symput(cats('FILELIST',put(_N_,best.))),catx(' ',symget('FILELIST'),EXTERNALNAMES);&lt;BR /&gt;
* save count of FILELISTX created;&lt;BR /&gt;
call symput('FILELISTN', put(_N_,best.));&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
After that you'll get,[pre]&lt;BR /&gt;
FILELIST1=n:\data\data01\excelfile.xls&lt;BR /&gt;
FILELIST2=n:\data\data02\excelfile.xls&lt;BR /&gt;
...&lt;BR /&gt;
FILELISTN=N&lt;BR /&gt;
[/pre]&lt;BR /&gt;
being N the total count of files to be imported.&lt;BR /&gt;
&lt;BR /&gt;
Then you just need to issue a proc import for each FILELISTX using a macro loop...&lt;BR /&gt;
[pre]&lt;BR /&gt;
%macro load_data;&lt;BR /&gt;
&lt;BR /&gt;
* erase data of previous run, if any;&lt;BR /&gt;
proc datasets lib=WORK nolist;&lt;BR /&gt;
delete INDATA:;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
* loop to total count of files;&lt;BR /&gt;
%do I=1 %to &amp;amp;FILELISTN;&lt;BR /&gt;
&lt;BR /&gt;
* import file;&lt;BR /&gt;
proc import out=WORK.INDATA&amp;amp;I&lt;BR /&gt;
file="&amp;amp;&amp;amp;FILELIST&amp;amp;I"&lt;BR /&gt;
dbms=xls replace;&lt;BR /&gt;
getnames=yes;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
* append data;&lt;BR /&gt;
proc append base=INDATA data=INDATA&amp;amp;I force;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%end;&lt;BR /&gt;
%mem load_data;&lt;BR /&gt;
&lt;BR /&gt;
%load_data; * run macro;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Finally you should get a WORK.INDATA dataset with the concatenated data imported from the specified excel files.&lt;BR /&gt;
&lt;BR /&gt;
Code above not tested!&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;</description>
      <pubDate>Fri, 05 Feb 2010 10:26:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Read-in-multiple-excel-text-files/m-p/15248#M2647</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2010-02-05T10:26:01Z</dc:date>
    </item>
    <item>
      <title>Re: Read in multiple excel/text  files</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Read-in-multiple-excel-text-files/m-p/15249#M2648</link>
      <description>Suggestion to OP Norman21 - considering it's your first post, suggesting you want to create new posts on the forums when you have a question/problem/discussion item, instead of piggy-backing on another individual's prior post - if you want to reference a prior post, then past a link to it in your "new" post.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 05 Feb 2010 14:03:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Read-in-multiple-excel-text-files/m-p/15249#M2648</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-02-05T14:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: Read in multiple excel/text  files</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Read-in-multiple-excel-text-files/m-p/15250#M2649</link>
      <description>Hi Daniel,&lt;BR /&gt;
&lt;BR /&gt;
Thanks for this, but it gives an error (the first underline is at the comma before catx):&lt;BR /&gt;
&lt;BR /&gt;
7    call symput(cats('FILELIST',put(_N_,best.))),catx(' ',symget('FILELIST'),EXTERNALNAMES);&lt;BR /&gt;
                                                 -                                          -&lt;BR /&gt;
                                                 79                                         22&lt;BR /&gt;
                                                 200                                        76&lt;BR /&gt;
          ------&lt;BR /&gt;
          252&lt;BR /&gt;
ERROR: Undeclared array referenced: catx.&lt;BR /&gt;
ERROR 79-322: Expecting a ;.&lt;BR /&gt;
&lt;BR /&gt;
ERROR 22-322: Syntax error, expecting one of the following: +, =.&lt;BR /&gt;
&lt;BR /&gt;
ERROR 200-322: The symbol is not recognized and will be ignored.&lt;BR /&gt;
&lt;BR /&gt;
ERROR 76-322: Syntax error, statement will be ignored.&lt;BR /&gt;
&lt;BR /&gt;
ERROR 252-185: The SYMPUT subroutine call does not have enough arguments.&lt;BR /&gt;
&lt;BR /&gt;
8    * save count of FILELISTX created;&lt;BR /&gt;
9    call symput('FILELISTN', put(_N_,best.));&lt;BR /&gt;
10   run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;
&lt;BR /&gt;
And in future I'll create a new post for a new question!</description>
      <pubDate>Sat, 06 Feb 2010 09:01:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Read-in-multiple-excel-text-files/m-p/15250#M2649</guid>
      <dc:creator>Norman21</dc:creator>
      <dc:date>2010-02-06T09:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: Read in multiple excel/text  files</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Read-in-multiple-excel-text-files/m-p/15251#M2650</link>
      <description>Right from the start, the SAS DOC for CALL SYMPUT shows only two arguments -- from the executed code, I see at least three arguments - likely parenthese location.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Sat, 06 Feb 2010 15:54:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Read-in-multiple-excel-text-files/m-p/15251#M2650</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-02-06T15:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: Read in multiple excel/text  files</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Read-in-multiple-excel-text-files/m-p/15252#M2651</link>
      <description>Yes. Misplaced parenthese. I did not got the time to test the code, the correct syntax would be:&lt;BR /&gt;
[pre]&lt;BR /&gt;
call symput( cats('FILELIST',put(_N_,best.)), catx(' ',symget('FILELIST'),EXTERNALNAMES) );&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;</description>
      <pubDate>Mon, 08 Feb 2010 14:16:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Read-in-multiple-excel-text-files/m-p/15252#M2651</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2010-02-08T14:16:36Z</dc:date>
    </item>
    <item>
      <title>Re: Read in multiple excel/text  files</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Read-in-multiple-excel-text-files/m-p/15253#M2652</link>
      <description>An update on my problem....&lt;BR /&gt;
&lt;BR /&gt;
It turns out the files with an XLS suffix are not Excel files, although they can be opened with Excel.  I've had to do the task by hand - open each file in turn, and copy/paste the rows to a "master" Excel file.  Crude but effective.</description>
      <pubDate>Sun, 23 May 2010 16:07:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Read-in-multiple-excel-text-files/m-p/15253#M2652</guid>
      <dc:creator>Norman21</dc:creator>
      <dc:date>2010-05-23T16:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: Read in multiple excel/text  files</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Read-in-multiple-excel-text-files/m-p/15254#M2653</link>
      <description>sas is more effective.&lt;BR /&gt;
Since these are not excel files but text files like CSV, an optimal solution might be to use pipe like[pre]filename myfiles pipe "dir /s/b ""mypathfile*pattern"" " lrecl=1000 ;[/pre]which searches for files named according to the name pattern you seek in the path defined, and returns infile buffers with the path\filenames.&lt;BR /&gt;
This data step would load a text version of the first 10 columns from each of these files [pre] data loaded_as_text( compress=yes keep= col1-col10 file) ;&lt;BR /&gt;
   length col1-col10 $20 fil file $500;&lt;BR /&gt;
   infile myfiles truncover ;&lt;BR /&gt;
   input fil $500. ;&lt;BR /&gt;
   if fil ne ' ' then do ;&lt;BR /&gt;
      file_finished = 0;&lt;BR /&gt;
      infile  dum filevar= fil dsd dlm= ',' missover end= file_finished ;&lt;BR /&gt;
      file = fil ;&lt;BR /&gt;
      do while( not file_finished );&lt;BR /&gt;
         input col1 - col10 ;&lt;BR /&gt;
         output ;&lt;BR /&gt;
      end ;&lt;BR /&gt;
   end ;&lt;BR /&gt;
run ;[/pre]The syntax of the command returning the list of path\filenames is op.sys specific and the demo is for windows.&lt;BR /&gt;
 &lt;BR /&gt;
&lt;B&gt;it is the absence of manual handling (cut-n-paste) that makes it more effective&lt;I&gt;&lt;BR /&gt;
imho&lt;/I&gt;&lt;/B&gt;&lt;I&gt;&lt;/I&gt;&lt;BR /&gt;
 &lt;BR /&gt;
peterC</description>
      <pubDate>Mon, 31 May 2010 08:54:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Read-in-multiple-excel-text-files/m-p/15254#M2653</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-05-31T08:54:12Z</dc:date>
    </item>
  </channel>
</rss>

