<?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 PROC IMPORT MACRO Importing multiple files - file name begins with &amp;quot;Test&amp;quot; in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-MACRO-Importing-multiple-files-file-name-begins-with/m-p/853385#M337302</link>
    <description>&lt;P&gt;Good Evening All, please assist in the following scenario as i'm trying to import multiple EXCEL files using proc Import macro and file names begin with "test". Can I apply this wild card test% in the MEND statement so that all the files that begin with test will be imported. Please see example im trying to use&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro Import_file(VENDORFILE);&lt;BR /&gt;PROC IMPORT&lt;BR /&gt;DATAFILE= "File directory location"&lt;BR /&gt;RUN;&lt;BR /&gt;%MEND test%;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you all in advance.&lt;/P&gt;</description>
    <pubDate>Thu, 12 Jan 2023 03:47:04 GMT</pubDate>
    <dc:creator>pappusrini</dc:creator>
    <dc:date>2023-01-12T03:47:04Z</dc:date>
    <item>
      <title>PROC IMPORT MACRO Importing multiple files - file name begins with "Test"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-MACRO-Importing-multiple-files-file-name-begins-with/m-p/853385#M337302</link>
      <description>&lt;P&gt;Good Evening All, please assist in the following scenario as i'm trying to import multiple EXCEL files using proc Import macro and file names begin with "test". Can I apply this wild card test% in the MEND statement so that all the files that begin with test will be imported. Please see example im trying to use&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro Import_file(VENDORFILE);&lt;BR /&gt;PROC IMPORT&lt;BR /&gt;DATAFILE= "File directory location"&lt;BR /&gt;RUN;&lt;BR /&gt;%MEND test%;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you all in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2023 03:47:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-MACRO-Importing-multiple-files-file-name-begins-with/m-p/853385#M337302</guid>
      <dc:creator>pappusrini</dc:creator>
      <dc:date>2023-01-12T03:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IMPORT MACRO Importing multiple files - file name begins with "Test"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-MACRO-Importing-multiple-files-file-name-begins-with/m-p/853386#M337303</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/210038"&gt;@pappusrini&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Good Evening All, please assist in the following scenario as i'm trying to import multiple EXCEL files using proc Import macro and file names begin with "test". Can I apply this wild card test% in the MEND statement so that all the files that begin with test will be imported. Please see example im trying to use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro Import_file(VENDORFILE);&lt;BR /&gt;PROC IMPORT&lt;BR /&gt;DATAFILE= "File directory location"&lt;BR /&gt;RUN;&lt;BR /&gt;%MEND test%;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you all in advance.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No.&amp;nbsp; That does not make any sense at all.&amp;nbsp; The only text you should have on the %MEND statement is the same name as you ahve on the %MACRO statement.&amp;nbsp; If you put something different there then SAS will write a note in the log to let you know that you probably have either made a typo or messed up something else that is causing it to skip one of the %MACRO or %MEND statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to import multiple physical XLSX files you will need run multiple steps.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import dbms=xlsx file="somefile.xlsx" out=somedsname replace;
run;
proc import dbms=xlsx file="otherfile.xlsx" out=otherdsname replace;
run;
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to import multiple sheets from a single XLSX file it might be easier to use the XLSX libref engine instead of PROC IMPORT.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname in xlsx "something.xlsx";
libname out "some directory";
proc copy inlib=in outlib=out;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have a macro that can import one XLSX file and a dataset with the list of XLSX files to import you can use a data step to CALL the macro multiple times, each time passing in a different filename.&amp;nbsp; Note the macro you showed is NOT a working macro to import an XLSX file.&amp;nbsp; But assuming you did have a macro named %IMPORT_FILE() that did work, then the data step might look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set filelist;
  where upcase(filename) like 'TEST%.XLSX';
  call execute(cats('%nrstr(%import_file)(',filename,')'));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Jan 2023 04:02:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-MACRO-Importing-multiple-files-file-name-begins-with/m-p/853386#M337303</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-12T04:02:56Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IMPORT MACRO Importing multiple files - file name begins with "Test"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-MACRO-Importing-multiple-files-file-name-begins-with/m-p/853387#M337304</link>
      <description>Thanks Tom… I’m trying to import multiple files from the folder. After the %Mend statement if I call the macro name along with the file names it will run. Here is the example:&lt;BR /&gt;&lt;BR /&gt;%mend;&lt;BR /&gt;%Macroname (testfile1);&lt;BR /&gt;%Macroname (testfile2); etc&lt;BR /&gt;&lt;BR /&gt;My question is rather than typing these file names manually can I bring all the files at once using wildcard test%&lt;BR /&gt;&lt;BR /&gt;Sorry if I’m confusing you with my question.&lt;BR /&gt;</description>
      <pubDate>Thu, 12 Jan 2023 04:13:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-MACRO-Importing-multiple-files-file-name-begins-with/m-p/853387#M337304</guid>
      <dc:creator>pappusrini</dc:creator>
      <dc:date>2023-01-12T04:13:53Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IMPORT MACRO Importing multiple files - file name begins with "Test"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-MACRO-Importing-multiple-files-file-name-begins-with/m-p/853390#M337305</link>
      <description>&lt;P&gt;So your question is not about how to run the macro.&amp;nbsp; It its about how to discover the names of the files.&lt;/P&gt;
&lt;P&gt;That question has been answered many times on this list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The easiest is to just ask your operating system to tell you names of the files.&lt;/P&gt;
&lt;P&gt;For example if your SAS program is running on Unix just use the ls command.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data files ;
  infile "ls /mydirectoryname/test*.xlsx" pipe truncover;
  input filename $256. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you have the data you need to run the data step I showed you before to call the macro multiple times.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your system admins have disabled the ability for you to run operating system commands then you will need to work harder.&lt;/P&gt;
&lt;P&gt;So use something like this macro to get the list of files:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/sasutils/macros/blob/master/dirtree.sas" target="_blank"&gt;https://github.com/sasutils/macros/blob/master/dirtree.sas&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2023 05:18:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-MACRO-Importing-multiple-files-file-name-begins-with/m-p/853390#M337305</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-12T05:18:02Z</dc:date>
    </item>
  </channel>
</rss>

