<?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: Combine multiple Excel files containing specific text in their file names into a single SAS tabl in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-Excel-files-containing-specific-text-in-their/m-p/745821#M233875</link>
    <description>&lt;P&gt;Only keep the XLSX files in your list.&amp;nbsp; For example by adding a subsetting IF statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  if lowcase(scan(myfiles,-1,'.')='xlsx';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Updated macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro MultImp(dir=,out=);

filename myfiles pipe %bquote('dir "&amp;amp;dir\" /A-D/B/ON');

data list;
  length fname $256 ;
  infile myfiles truncover;
  input myfiles $100.;
  if lowcase(scan(myfiles,-1,'.')='xlsx';
  fname=quote(cats("&amp;amp;dir",'\',myfiles));
  out="&amp;amp;out";
  drop myfiles;
  call execute(catx(' '
    ,'proc import dbms=xlsx out= _test datafile=',fname,'replace;run;'
    ,'proc append data=_test base=',out,'force;run;'
    ,'proc delete data=_test; run;'
  ));
run;

filename myfiles clear;

%mend;

%MultImp(dir=G:\MY DRIVE\Folder\test,out=merged);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Note&lt;/STRONG&gt; make sure you have complete control over how the data is entered into those XLSX sheets.&amp;nbsp; Otherwise your PROC APPEND step will fail when variables had the wrong type on some of the XLSX files.&lt;/P&gt;</description>
    <pubDate>Fri, 04 Jun 2021 15:32:41 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-06-04T15:32:41Z</dc:date>
    <item>
      <title>Combine multiple Excel files containing specific text in their file names into a single SAS table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-Excel-files-containing-specific-text-in-their/m-p/745807#M233864</link>
      <description>&lt;P&gt;I found a helpful macro function to import multiple Excel files and combine them into a single SAS table from &lt;A href="https://www.listendata.com/2013/10/sas-importing-multiple-excel-files-in.html" target="_self"&gt;https://www.listendata.com/2013/10/sas-importing-multiple-excel-files-in.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro MultImp(dir=,out=);

%let rc=%str(%'dir %")&amp;amp;dir.%str(\%" /A-D/B/ON%');
filename myfiles pipe %unquote(&amp;amp;rc);

data list;
length fname $256.;
infile myfiles truncover;
input myfiles $100.;

fname=quote(upcase(cats("&amp;amp;dir",'\',myfiles)));
out="&amp;amp;out";
drop myfiles;
call execute('
  proc import dbms=xlsx out= _test
            datafile= '||fname||' replace ;
  run;
  proc append data=_test base='||out||' force; run;
  proc delete data=_test; run;
');
run;
filename myfiles clear;

%mend;

%MultImp(dir=G:\MY DRIVE\Folder\test,out=merged);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;However, if the folder contains something other than an Excel file, the import fails:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR: Error opening XLSX file -&amp;gt; G:\MY DRIVE\Folder\desktop.ini.xlsx .  It is either not an 
Excel spreadsheet or it is damaged.   Error code=8014900A
Requested Input File Is Invalid
ERROR: Import unsuccessful.  See SAS Log for details.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How can I ensure that the function only attempts to import .xlsx files containing a specific text string in the filename?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the help.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 14:22:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-Excel-files-containing-specific-text-in-their/m-p/745807#M233864</guid>
      <dc:creator>avz</dc:creator>
      <dc:date>2021-06-04T14:22:30Z</dc:date>
    </item>
    <item>
      <title>Re: Combine multiple Excel files containing specific text in their file names into a single SAS tabl</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-Excel-files-containing-specific-text-in-their/m-p/745816#M233872</link>
      <description>&lt;P&gt;This is technically a DOS question.&amp;nbsp; Run these lines so you can see the RC macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dir=MYfiles;
%let rc=%str(%'dir %")&amp;amp;dir.%str(\%" /A-D/B/ON%');

%put NOTE: &amp;amp;=rc;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and run this line in a DOS shell to see how to use the DOS command that you are using.&lt;/P&gt;
&lt;PRE&gt;dir /?&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Jun 2021 15:14:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-Excel-files-containing-specific-text-in-their/m-p/745816#M233872</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-06-04T15:14:01Z</dc:date>
    </item>
    <item>
      <title>Re: Combine multiple Excel files containing specific text in their file names into a single SAS tabl</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-Excel-files-containing-specific-text-in-their/m-p/745819#M233874</link>
      <description>&lt;PRE&gt;%macro MultImp(dir=,out=);

%let rc=%str(%'dir %")&amp;amp;dir.%str(\%" /A-D/B/ON%');
filename myfiles pipe %unquote(&amp;amp;rc);

data list;
length fname $256.;
infile myfiles truncover;
input myfiles $100.;

fname=quote(upcase(cats("&amp;amp;dir",'\',myfiles)));
out="&amp;amp;out";
drop myfiles;

&lt;FONT size="4" color="#FF0000"&gt;&lt;STRONG&gt;if find(fname, "xlsx", 'it') then&lt;/STRONG&gt; &lt;/FONT&gt;
call execute('
  proc import dbms=xlsx out= _test
            datafile= '||fname||' replace ;
  run;
  proc append data=_test base='||out||' force; run;
  proc delete data=_test; run;
');
run;
filename myfiles clear;

%mend;

%MultImp(dir=G:\MY DRIVE\Folder\test,out=merged);&lt;/PRE&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p00ab6ey29t2i8n1ihel88tqtga9.htm" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p00ab6ey29t2i8n1ihel88tqtga9.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Only import if the file is XLSX.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 15:20:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-Excel-files-containing-specific-text-in-their/m-p/745819#M233874</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-04T15:20:20Z</dc:date>
    </item>
    <item>
      <title>Re: Combine multiple Excel files containing specific text in their file names into a single SAS tabl</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-Excel-files-containing-specific-text-in-their/m-p/745821#M233875</link>
      <description>&lt;P&gt;Only keep the XLSX files in your list.&amp;nbsp; For example by adding a subsetting IF statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  if lowcase(scan(myfiles,-1,'.')='xlsx';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Updated macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro MultImp(dir=,out=);

filename myfiles pipe %bquote('dir "&amp;amp;dir\" /A-D/B/ON');

data list;
  length fname $256 ;
  infile myfiles truncover;
  input myfiles $100.;
  if lowcase(scan(myfiles,-1,'.')='xlsx';
  fname=quote(cats("&amp;amp;dir",'\',myfiles));
  out="&amp;amp;out";
  drop myfiles;
  call execute(catx(' '
    ,'proc import dbms=xlsx out= _test datafile=',fname,'replace;run;'
    ,'proc append data=_test base=',out,'force;run;'
    ,'proc delete data=_test; run;'
  ));
run;

filename myfiles clear;

%mend;

%MultImp(dir=G:\MY DRIVE\Folder\test,out=merged);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Note&lt;/STRONG&gt; make sure you have complete control over how the data is entered into those XLSX sheets.&amp;nbsp; Otherwise your PROC APPEND step will fail when variables had the wrong type on some of the XLSX files.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 15:32:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-Excel-files-containing-specific-text-in-their/m-p/745821#M233875</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-04T15:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: Combine multiple Excel files containing specific text in their file names into a single SAS tabl</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-Excel-files-containing-specific-text-in-their/m-p/745859#M233900</link>
      <description>Thank you, Reeza.</description>
      <pubDate>Fri, 04 Jun 2021 17:10:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-Excel-files-containing-specific-text-in-their/m-p/745859#M233900</guid>
      <dc:creator>avz</dc:creator>
      <dc:date>2021-06-04T17:10:04Z</dc:date>
    </item>
  </channel>
</rss>

