<?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: Import multiple xlsx files with multiple sheets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Import-multiple-xlsx-files-with-multiple-sheets/m-p/561480#M157196</link>
    <description>&lt;P&gt;What I want is to import all files in a directory and at the same time, import specific sheets from those files&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 24 May 2019 16:57:04 GMT</pubDate>
    <dc:creator>Mxmaverick</dc:creator>
    <dc:date>2019-05-24T16:57:04Z</dc:date>
    <item>
      <title>Import multiple xlsx files with multiple sheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-multiple-xlsx-files-with-multiple-sheets/m-p/561446#M157169</link>
      <description>&lt;P&gt;Hi everyone, I just wanted to know if anyone knows how to import many excel files and at the same time, import specific sheets from this files. I already have a macro that can do both process but separately. Thank in advance. BTW this are my two codes&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;THIS ONE IMPORT MULTIPLE FILES&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro MultImp(dir=,out=);&lt;/P&gt;&lt;P&gt;%let rc=%str(%'dir %")&amp;amp;dir.%str(\%" /A-D/B/ON%');&lt;BR /&gt;filename myfiles pipe %unquote(&amp;amp;rc);&lt;/P&gt;&lt;P&gt;data list;&lt;BR /&gt;length fname $256.;&lt;BR /&gt;infile myfiles truncover;&lt;BR /&gt;input myfiles $100.;&lt;/P&gt;&lt;P&gt;fname=quote(upcase(cats("&amp;amp;dir",'\',myfiles)));&lt;BR /&gt;out="&amp;amp;out";&lt;BR /&gt;drop myfiles;&lt;BR /&gt;call execute('&lt;BR /&gt;proc import dbms=xlsx out= _test&lt;BR /&gt;datafile= '||fname||' replace ;&lt;BR /&gt;run;&lt;BR /&gt;proc append data=_test base='||out||' force; run;&lt;BR /&gt;proc delete data=_test; run;&lt;BR /&gt;');&lt;BR /&gt;run;&lt;BR /&gt;filename myfiles clear;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;proc import dbms=xlsx out= merged&lt;BR /&gt;datafile= "C:\USERS\.....\.XLSX" replace ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%MultImp(dir=C:\Users\Usuario\Desktop\Prompts\Para_Promp_1\Originales\Empresas_Certificadas_V2\Empresas_Certificadas_Despacho_de_Mercancías_98LA,out=merged);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and THIS ONE IMPORT MULTIPLE SHEETS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro dataload(sheet);&lt;/P&gt;&lt;P&gt;proc import out= &amp;amp;sheet&lt;BR /&gt;datafile = 'C:\Users\...\.....xlsx'&lt;BR /&gt;dbms = xlsx replace;&lt;BR /&gt;sheet = "&amp;amp;sheet";&lt;BR /&gt;getnames = yes;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%mend dataload;&lt;BR /&gt;%dataload(sheet1);&lt;BR /&gt;%dataload(sheet2);&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2019 15:46:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-multiple-xlsx-files-with-multiple-sheets/m-p/561446#M157169</guid>
      <dc:creator>Mxmaverick</dc:creator>
      <dc:date>2019-05-24T15:46:28Z</dc:date>
    </item>
    <item>
      <title>Re: Import multiple xlsx files with multiple sheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-multiple-xlsx-files-with-multiple-sheets/m-p/561452#M157174</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro importXLSX(path=);

libname myfile XLSX "&amp;amp;path";

proc copy in=myfile out=work;
run;

libname myfile;

%mend;

%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;

str = catt('%importXLSX(path=', fname, ');');

call execute (str);

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your macro imports and appends the file to a single format. Are you expecting that as well. Otherwise, something like the above may work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Make a macro to import all files from one XLSX doc using LIBNAME&lt;/P&gt;
&lt;P&gt;2. Call macro for each XLSX file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/275425"&gt;@Mxmaverick&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi everyone, I just wanted to know if anyone knows how to import many excel files and at the same time, import specific sheets from this files. I already have a macro that can do both process but separately. Thank in advance. BTW this are my two codes&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;THIS ONE IMPORT MULTIPLE FILES&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro MultImp(dir=,out=);&lt;/P&gt;
&lt;P&gt;%let rc=%str(%'dir %")&amp;amp;dir.%str(\%" /A-D/B/ON%');&lt;BR /&gt;filename myfiles pipe %unquote(&amp;amp;rc);&lt;/P&gt;
&lt;P&gt;data list;&lt;BR /&gt;length fname $256.;&lt;BR /&gt;infile myfiles truncover;&lt;BR /&gt;input myfiles $100.;&lt;/P&gt;
&lt;P&gt;fname=quote(upcase(cats("&amp;amp;dir",'\',myfiles)));&lt;BR /&gt;out="&amp;amp;out";&lt;BR /&gt;drop myfiles;&lt;BR /&gt;call execute('&lt;BR /&gt;proc import dbms=xlsx out= _test&lt;BR /&gt;datafile= '||fname||' replace ;&lt;BR /&gt;run;&lt;BR /&gt;proc append data=_test base='||out||' force; run;&lt;BR /&gt;proc delete data=_test; run;&lt;BR /&gt;');&lt;BR /&gt;run;&lt;BR /&gt;filename myfiles clear;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;proc import dbms=xlsx out= merged&lt;BR /&gt;datafile= "C:\USERS\.....\.XLSX" replace ;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%MultImp(dir=C:\Users\Usuario\Desktop\Prompts\Para_Promp_1\Originales\Empresas_Certificadas_V2\Empresas_Certificadas_Despacho_de_Mercancías_98LA,out=merged);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and THIS ONE IMPORT MULTIPLE SHEETS&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro dataload(sheet);&lt;/P&gt;
&lt;P&gt;proc import out= &amp;amp;sheet&lt;BR /&gt;datafile = 'C:\Users\...\.....xlsx'&lt;BR /&gt;dbms = xlsx replace;&lt;BR /&gt;sheet = "&amp;amp;sheet";&lt;BR /&gt;getnames = yes;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%mend dataload;&lt;BR /&gt;%dataload(sheet1);&lt;BR /&gt;%dataload(sheet2);&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2019 15:55:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-multiple-xlsx-files-with-multiple-sheets/m-p/561452#M157174</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-05-24T15:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: Import multiple xlsx files with multiple sheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-multiple-xlsx-files-with-multiple-sheets/m-p/561480#M157196</link>
      <description>&lt;P&gt;What I want is to import all files in a directory and at the same time, import specific sheets from those files&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2019 16:57:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-multiple-xlsx-files-with-multiple-sheets/m-p/561480#M157196</guid>
      <dc:creator>Mxmaverick</dc:creator>
      <dc:date>2019-05-24T16:57:04Z</dc:date>
    </item>
    <item>
      <title>Re: Import multiple xlsx files with multiple sheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-multiple-xlsx-files-with-multiple-sheets/m-p/561481#M157197</link>
      <description>Modify the PROC COPY to select only the sheets of interest, using the SELECT statement. &lt;BR /&gt;proc copy in=mylib out=work;&lt;BR /&gt;select sheet1 sheet2;&lt;BR /&gt;run;</description>
      <pubDate>Fri, 24 May 2019 16:59:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-multiple-xlsx-files-with-multiple-sheets/m-p/561481#M157197</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-05-24T16:59:21Z</dc:date>
    </item>
  </channel>
</rss>

