<?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: Excel sheet name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Excel-sheet-name/m-p/483999#M125582</link>
    <description>&lt;PRE&gt;
Or could try other engine.

libname xls xls '/u1/excel/Listing.xls';

libname xls excel  '/u1/excel/Listing.xls';


&lt;/PRE&gt;</description>
    <pubDate>Sat, 04 Aug 2018 10:56:38 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-08-04T10:56:38Z</dc:date>
    <item>
      <title>Excel sheet name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excel-sheet-name/m-p/483927#M125557</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to get excel sheet names into macro variable. Can anybody help me how to do that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using below code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;libname xls xlsx&amp;nbsp; '/u1/excel/Listing.xlsx';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But it shows below error:&lt;/P&gt;&lt;P&gt;ERROR: The XLSX engine cannot be found.&lt;BR /&gt;ERROR: Error in the LIBNAME statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 21:20:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excel-sheet-name/m-p/483927#M125557</guid>
      <dc:creator>petlove</dc:creator>
      <dc:date>2018-08-03T21:20:39Z</dc:date>
    </item>
    <item>
      <title>Re: Excel sheet name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excel-sheet-name/m-p/483940#M125559</link>
      <description>&lt;P&gt;What SAS version and maintenance release are you using? You need to be on SAS 9.4M2 or higher for this to work:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=acpcref&amp;amp;docsetTarget=acpcrefwhatsnew94.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=acpcref&amp;amp;docsetTarget=acpcrefwhatsnew94.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also SAS/ACCESS to PC Files needs to be installed and licensed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 23:14:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excel-sheet-name/m-p/483940#M125559</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2018-08-03T23:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: Excel sheet name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excel-sheet-name/m-p/483999#M125582</link>
      <description>&lt;PRE&gt;
Or could try other engine.

libname xls xls '/u1/excel/Listing.xls';

libname xls excel  '/u1/excel/Listing.xls';


&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 Aug 2018 10:56:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excel-sheet-name/m-p/483999#M125582</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-08-04T10:56:38Z</dc:date>
    </item>
    <item>
      <title>Re: Excel sheet name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excel-sheet-name/m-p/484064#M125601</link>
      <description>&lt;P&gt;I had a macro that could read the sheet names from the XML data inside the XLSX file that I used before SAS released the XLSX engine.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro xlsx
/*----------------------------------------------------------------------
Macro for reading sheets from XLSX files
----------------------------------------------------------------------*/
(filename       /* Physical name of XLSX file to read. */
,sheets=        /* Dataset name to hold list of sheets.  */
,import=        /* Run code to import sheets? (0/1) */
,libref=        /* Where to write the imported sheets. (default=WORK) */
,getnames=      /* Setting of GETNAMES option. (yes/no) (default=yes) */
,hidden=        /* Include sheets with state="hidden"? (0/1) */
);
%local macro parmerr nsheets ;
%let macro=&amp;amp;sysmacroname;
%let parmerr=0;

%*----------------------------------------------------------------------
Check if using recent enough version of SAS.
-----------------------------------------------------------------------;
%if %sysevalf(&amp;amp;sysver &amp;lt; 9.4) %then %parmv(_msg=Requires SAS 9.4 or up);
%if (&amp;amp;parmerr) %then %goto quit;

%*----------------------------------------------------------------------
Validate user parameters.
-----------------------------------------------------------------------;
%if (%bquote(&amp;amp;filename)=) %then %parmv(_msg=Filename is required);
%else %do;
  %if ^%sysfunc(fileexist(&amp;amp;filename)) %then
    %parmv(_msg=Filename &amp;amp;filename does not exist) ;
  %else %let filename=%sysfunc(quote(%qsysfunc(dequote(&amp;amp;filename)))) ;
%end;

%parmv(import,_val=0 1,_def=%eval(0&amp;lt;%length(&amp;amp;libref)))
%parmv(libref,_def=work)
%if %length(&amp;amp;libref)&amp;gt;8 %then %parmv(LIBREF,_msg=Maximum length of 8);
%else %if %sysfunc(libref(&amp;amp;libref)) %then
  %parmv(LIBREF,_msg=&amp;amp;libref is not assigned)
;

%parmv(sheets,_req=0)
%parmv(getnames,_val=yes no,_case=l,_def=yes)
%parmv(hidden,_val=0 1,_def=0)

%if (&amp;amp;parmerr) %then %goto quit;

*----------------------------------------------------------------------;
* Generate XMLMAP to read the sheetnames from xl/workbook.xml ;
*----------------------------------------------------------------------;
filename _wbmap temp;
data _null_;
  file _wbmap;
  put '&amp;lt;SXLEMAP version="2.1"&amp;gt;&amp;lt;TABLE name="Sheets"&amp;gt;'
    / '&amp;lt;TABLE-PATH&amp;gt;/workbook/sheets/sheet&amp;lt;/TABLE-PATH&amp;gt;'
    / '&amp;lt;COLUMN name="Sheet"&amp;gt;&amp;lt;TYPE&amp;gt;character&amp;lt;/TYPE&amp;gt;'
    / '&amp;lt;DESCRIPTION&amp;gt;Sheet Name&amp;lt;/DESCRIPTION&amp;gt;'
    / '&amp;lt;PATH&amp;gt;/workbook/sheets/sheet/@name&amp;lt;/PATH&amp;gt;'
    / '&amp;lt;DATATYPE&amp;gt;string&amp;lt;/DATATYPE&amp;gt;&amp;lt;LENGTH&amp;gt;32&amp;lt;/LENGTH&amp;gt;'
    / '&amp;lt;/COLUMN&amp;gt;'
    / '&amp;lt;COLUMN name="State"&amp;gt;&amp;lt;TYPE&amp;gt;character&amp;lt;/TYPE&amp;gt;'
    / '&amp;lt;DESCRIPTION&amp;gt;Sheet State&amp;lt;/DESCRIPTION&amp;gt;'
    / '&amp;lt;PATH&amp;gt;/workbook/sheets/sheet/@state&amp;lt;/PATH&amp;gt;'
    / '&amp;lt;DATATYPE&amp;gt;string&amp;lt;/DATATYPE&amp;gt;&amp;lt;LENGTH&amp;gt;20&amp;lt;/LENGTH&amp;gt;'
    / '&amp;lt;/COLUMN&amp;gt;'
    / '&amp;lt;/TABLE&amp;gt;&amp;lt;/SXLEMAP&amp;gt;'
  ;
run;

*----------------------------------------------------------------------;
* Generate LIBNAME pointing to xl/workbook.xml inside the XLSX file ;
%* Note: Cannot use ZIP filename engine with XMLV2 libname engine ;
*----------------------------------------------------------------------;
filename _wb pipe %sysfunc(quote(unzip -p &amp;amp;filename xl/workbook.xml));
libname _wb xmlv2 xmlmap=_wbmap ;

*----------------------------------------------------------------------;
* Read sheet names from XLSX file into a SAS dataset. ;
* Create valid SAS dataset name from sheetname or sheetnumber. ;
* Generate PROC IMPORT code to convert sheets into datasets. ;
*----------------------------------------------------------------------;
filename extract temp;
data &amp;amp;sheets ;
  file extract ;
  if _n_=1 then do ;
    put "* Generated by &amp;amp;macro macro @%sysfunc(datetime(),datetime19.);" ;
  end;
  if eof then call symputx('nsheets',_n_-1);
  length Number 8;
  set _wb.sheets end=eof;
  number+1;
  length Memname $32 Filename $256 ;
  label number='Sheet Number' memname='Mapped SAS Memname' filename='Source File
name' ;
  filename = &amp;amp;filename ;
  if ^nvalid(compress(sheet),'v7') then memname = cats('Sheet',number);
  else memname = translate(trim(compbl(sheet)),'_',' ');
%if (^&amp;amp;hidden) %then if state ne 'hidden' then ;
  put
    / 'proc import datafile=' %sysfunc(quote(&amp;amp;filename)) ' dbms=xlsx'
    / "  out=&amp;amp;libref.." memname '(label=' sheet :quote. ') replace'
    / ';'
    / "  getnames=&amp;amp;getnames;"
    / @3 sheet= :$quote. ';'
    / 'run;'
  ;
run;
%let sheets=&amp;amp;syslast;

*----------------------------------------------------------------------;
* Clear the libname and filenames used in reading the sheetnames. ;
*----------------------------------------------------------------------;
libname _wb clear ;
filename _wb clear ;
filename _wbmap clear ;

%if (&amp;amp;import) %then %do;
*----------------------------------------------------------------------;
* Run the generated PROC IMPORT code. ;
*----------------------------------------------------------------------;
  %inc extract ;
%end;

%*----------------------------------------------------------------------
Generate summary messages for user to the SASLOG .
-----------------------------------------------------------------------;
%if ^&amp;amp;nsheets %then %parmv(_msg=No worksheets found in &amp;amp;filename);
%else %do;
  %put ;
  %put NOTE: Worksheet list successfully read from file &amp;amp;filename.. ;
  %put NOTE: &amp;amp;sheets has information on &amp;amp;nsheets worksheets.;
  %if ^&amp;amp;import %then %put NOTE: PROC IMPORT code is in fileref EXTRACT.;
  %else %put NOTE: Worksheets were imported to &amp;amp;libref library.;
  %put ;
%end;

%quit:
%mend xlsx ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to try it you can find a copy of the parameter validation utility, %parmv(), here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/sasutils/macros/blob/master/parmv.sas" target="_blank"&gt;https://github.com/sasutils/macros/blob/master/parmv.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Aug 2018 21:38:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excel-sheet-name/m-p/484064#M125601</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-08-04T21:38:24Z</dc:date>
    </item>
  </channel>
</rss>

