<?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: macro for importing multiple excel sheets and multiple tabs within each excel sheet different na in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-for-importing-multiple-excel-sheets-and-multiple-tabs/m-p/947377#M370876</link>
    <description>&lt;P&gt;If you know the filename (workbook), sheetname and target dataset name for each worksheet then a macro with THREE input parameters should do what you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro import (workbook,outname,sheetname);
proc import datafile="&amp;amp;workbook" dbms=xlsx out=&amp;amp;outname replace ;
  sheetname="&amp;amp;sheetname";
run;
%mend import;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could even make it smart enough to not require the sheetname.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro import (workbook,outname,sheetname);
proc import datafile="&amp;amp;workbook" dbms=xlsx out=&amp;amp;outname replace ;
%if %length(&amp;amp;sheetname) %then %do;
  sheetname="&amp;amp;sheetname";
%end;
run;
%mend import;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In such cases it will just find the first worksheet in the workbook, like the macro you posted.&lt;/P&gt;</description>
    <pubDate>Mon, 14 Oct 2024 12:58:38 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-10-14T12:58:38Z</dc:date>
    <item>
      <title>macro for importing multiple excel sheets and multiple tabs within each excel sheet different names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-for-importing-multiple-excel-sheets-and-multiple-tabs/m-p/947373#M370873</link>
      <description>&lt;P&gt;Hi experts,&lt;/P&gt;&lt;P&gt;I am looking for some advice on how to import several excel sheets and&amp;nbsp; multiple tabs within each excel sheet&amp;nbsp; into SAS. I have used a macro before (attached SAS code here) but I had only one tab for each excel sheet. I found another SAS code (second code attached here) to import multiple tabs from one excel sheet, but it is importing only the first tab. Ideally I am looking for a combination of both...I need to import several excel sheets and data from multiple tabs within each excel sheet. I am also attaching excel sheets for example. Thank you in advance&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%macro import (df, outname);
proc import datafile="&amp;amp;df"
     out=&amp;amp;outname
     dbms=xlsx replace; 
    getnames=yes;
run;
%mend import;

%import (C:\Users\sm\Downloads\S Files\0h\DPA 0.5 0h\Example.xlsx, Example);
%import (C:\Users\sm\Downloads\S Files\0h\DPA 0.5 0h\Example1.xlsx, Example1);



%macro pim(sheet);
proc import out= DPA_05_1_0h_U7
    datafile = 'C:\Users\sm\Downloads\S Files\0h\DPA 0.5 0h\Example.xlsx'
    dbms = Excel;
    sheet = "&amp;amp;sheet";
    getnames = yes;
run;
%mend pim;
%pim(forces 10s (2));
%pim(moments 10s (2));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;for this!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SM&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Oct 2024 12:23:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-for-importing-multiple-excel-sheets-and-multiple-tabs/m-p/947373#M370873</guid>
      <dc:creator>sms1891</dc:creator>
      <dc:date>2024-10-14T12:23:08Z</dc:date>
    </item>
    <item>
      <title>Re: macro for importing multiple excel sheets and multiple tabs within each excel sheet different na</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-for-importing-multiple-excel-sheets-and-multiple-tabs/m-p/947375#M370875</link>
      <description>&lt;P&gt;Use LIBNAME XLSX for a workbook, and PROC COPY to transfer all sheets into SAS. Once that works for a single workbook file, wrap it into a macro which you can CALL EXECUTE from a DATA step that finds the files.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Oct 2024 12:46:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-for-importing-multiple-excel-sheets-and-multiple-tabs/m-p/947375#M370875</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-10-14T12:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: macro for importing multiple excel sheets and multiple tabs within each excel sheet different na</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-for-importing-multiple-excel-sheets-and-multiple-tabs/m-p/947377#M370876</link>
      <description>&lt;P&gt;If you know the filename (workbook), sheetname and target dataset name for each worksheet then a macro with THREE input parameters should do what you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro import (workbook,outname,sheetname);
proc import datafile="&amp;amp;workbook" dbms=xlsx out=&amp;amp;outname replace ;
  sheetname="&amp;amp;sheetname";
run;
%mend import;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could even make it smart enough to not require the sheetname.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro import (workbook,outname,sheetname);
proc import datafile="&amp;amp;workbook" dbms=xlsx out=&amp;amp;outname replace ;
%if %length(&amp;amp;sheetname) %then %do;
  sheetname="&amp;amp;sheetname";
%end;
run;
%mend import;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In such cases it will just find the first worksheet in the workbook, like the macro you posted.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Oct 2024 12:58:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-for-importing-multiple-excel-sheets-and-multiple-tabs/m-p/947377#M370876</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-10-14T12:58:38Z</dc:date>
    </item>
    <item>
      <title>Re: macro for importing multiple excel sheets and multiple tabs within each excel sheet different na</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-for-importing-multiple-excel-sheets-and-multiple-tabs/m-p/947404#M370884</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;Thanks for the reply. I am getting an error with the code.&amp;nbsp; If my workbook name is Example and the sheet name is forces.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;SM&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%macro import (workbook,outname,sheetname);
proc import datafile="&amp;amp;workbook" dbms=xlsx out=&amp;amp;outname replace ;
  sheetname="&amp;amp;sheetname";
run;
%mend import;
%import (C:\Users\sm\Downloads\Example.xlsx, forces, Example);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Oct 2024 17:09:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-for-importing-multiple-excel-sheets-and-multiple-tabs/m-p/947404#M370884</guid>
      <dc:creator>sms1891</dc:creator>
      <dc:date>2024-10-14T17:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: macro for importing multiple excel sheets and multiple tabs within each excel sheet different na</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-for-importing-multiple-excel-sheets-and-multiple-tabs/m-p/947405#M370885</link>
      <description>&lt;P&gt;Always &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/acpcref/n0msy4hy1so0ren1acm90iijxn8j.htm" target="_self"&gt;check the documentation&lt;/A&gt;.&amp;nbsp; I think the statement you want to have the macro generate is SHEET= not SHEETNAME=.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if the sheet is named forces why did you ask it to look for a sheet named Example?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Remember you can pass parameter values by NAME even when the macro is defined to also allow you pass them by position.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%import
(workbook=C:\Users\sm\Downloads\Example.xlsx
,sheetname=forces
,outname=Example
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Oct 2024 18:32:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-for-importing-multiple-excel-sheets-and-multiple-tabs/m-p/947405#M370885</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-10-14T18:32:15Z</dc:date>
    </item>
    <item>
      <title>Re: macro for importing multiple excel sheets and multiple tabs within each excel sheet different na</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-for-importing-multiple-excel-sheets-and-multiple-tabs/m-p/947449#M370902</link>
      <description>&lt;P&gt;Here some sample code to build upon for what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;suggested.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname src xlsx "c:\temp\Example.xlsx";
proc datasets lib=src nolist; 
  copy in=src out=work;
  run;
quit;
libname src clear;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Oct 2024 05:25:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-for-importing-multiple-excel-sheets-and-multiple-tabs/m-p/947449#M370902</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-10-15T05:25:48Z</dc:date>
    </item>
  </channel>
</rss>

