<?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: Extracting excel sheet name in sas in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extracting-excel-sheet-name-in-sas/m-p/898904#M355294</link>
    <description>/**Assign a libname for excel sheet*/&lt;BR /&gt;libname inexcel xlsx '/home/viadmin/casuser/mapping.xlsx';&lt;BR /&gt;&lt;BR /&gt;PROC CONTENTS DATA=inexcel._ALL_ noprint&lt;BR /&gt;OUT=Sheets (KEEP=Memname);&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;PROC SORT DATA=Sheets NODUPLICATES;&lt;BR /&gt;BY Memname;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;DATA Sheets;&lt;BR /&gt;SET Sheets;&lt;BR /&gt;ID=_N_;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;DATA _NULL_;&lt;BR /&gt;IF 0 THEN SET Sheets NOBS=X;&lt;BR /&gt;CALL SYMPUT('Recount', X);&lt;BR /&gt;STOP;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%macro Excel;&lt;BR /&gt;%DO i = 1 %TO &amp;amp;Recount;&lt;BR /&gt;PROC SQL ;&lt;BR /&gt;create table sheet&amp;amp;i. as&lt;BR /&gt;SELECT Memname INTO :Name&lt;BR /&gt;FROM Sheets WHERE ID = &amp;amp;i;&lt;BR /&gt;quit;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;&lt;BR /&gt;%excel;&lt;BR /&gt;&lt;BR /&gt;%dataload(target_table ='sheet&amp;amp;i.');&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I have done with, but i want that target_table automatically will be call %dataload(target_table ='sheet&amp;amp;i.');&lt;BR /&gt;&lt;BR /&gt;as sheet 1,&lt;BR /&gt;Like this-&lt;BR /&gt;%dataload(target_table ='sheet1.');&lt;BR /&gt;%dataload(target_table ='sheet2.');&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Tue, 17 Oct 2023 12:00:08 GMT</pubDate>
    <dc:creator>varshabansal</dc:creator>
    <dc:date>2023-10-17T12:00:08Z</dc:date>
    <item>
      <title>Extracting excel sheet name in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-excel-sheet-name-in-sas/m-p/898900#M355291</link>
      <description>&lt;P&gt;Hi everyone!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me,&amp;nbsp; I want to extracting all sheet name from my excel file and then want to use those sheet name as table names in my script dynamically.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Eg- sheet1. sheet2 are my sheet name&lt;/P&gt;&lt;P&gt;and sheet1 and sheet2 will be also my tablename&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2023 11:23:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-excel-sheet-name-in-sas/m-p/898900#M355291</guid>
      <dc:creator>varshabansal</dc:creator>
      <dc:date>2023-10-17T11:23:24Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting excel sheet name in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-excel-sheet-name-in-sas/m-p/898901#M355292</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/410614"&gt;@varshabansal&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname bjlist xlsx "/mnt/dwhadmin_prod/Work/pensiontjek_05-03-2023.xlsx";

proc contents data=bjlist._all_ noprint out=x;
run;

proc sql noprint;
   select distinct memname into :memlist separated by ' ' from x;
quit;
%put &amp;amp;=memlist;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The code above will gve a macro variable containing a list of sheet names.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2023 11:41:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-excel-sheet-name-in-sas/m-p/898901#M355292</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2023-10-17T11:41:04Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting excel sheet name in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-excel-sheet-name-in-sas/m-p/898902#M355293</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let excel= c:\temp\date.xlsx  ;   *path for inputing excel file;



options validvarname=any validmemname=extend;
libname x xlsx "&amp;amp;excel.";
data _null_;
 set sashelp.vtable(keep=memname libname where=(libname='X'));
call execute(catt('proc import datafile="&amp;amp;excel." out=',compress(memname,,'kda'),' dbms=xlsx replace;sheet="',memname,'";run;'));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Oct 2023 11:48:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-excel-sheet-name-in-sas/m-p/898902#M355293</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-10-17T11:48:08Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting excel sheet name in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-excel-sheet-name-in-sas/m-p/898904#M355294</link>
      <description>/**Assign a libname for excel sheet*/&lt;BR /&gt;libname inexcel xlsx '/home/viadmin/casuser/mapping.xlsx';&lt;BR /&gt;&lt;BR /&gt;PROC CONTENTS DATA=inexcel._ALL_ noprint&lt;BR /&gt;OUT=Sheets (KEEP=Memname);&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;PROC SORT DATA=Sheets NODUPLICATES;&lt;BR /&gt;BY Memname;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;DATA Sheets;&lt;BR /&gt;SET Sheets;&lt;BR /&gt;ID=_N_;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;DATA _NULL_;&lt;BR /&gt;IF 0 THEN SET Sheets NOBS=X;&lt;BR /&gt;CALL SYMPUT('Recount', X);&lt;BR /&gt;STOP;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%macro Excel;&lt;BR /&gt;%DO i = 1 %TO &amp;amp;Recount;&lt;BR /&gt;PROC SQL ;&lt;BR /&gt;create table sheet&amp;amp;i. as&lt;BR /&gt;SELECT Memname INTO :Name&lt;BR /&gt;FROM Sheets WHERE ID = &amp;amp;i;&lt;BR /&gt;quit;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;&lt;BR /&gt;%excel;&lt;BR /&gt;&lt;BR /&gt;%dataload(target_table ='sheet&amp;amp;i.');&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I have done with, but i want that target_table automatically will be call %dataload(target_table ='sheet&amp;amp;i.');&lt;BR /&gt;&lt;BR /&gt;as sheet 1,&lt;BR /&gt;Like this-&lt;BR /&gt;%dataload(target_table ='sheet1.');&lt;BR /&gt;%dataload(target_table ='sheet2.');&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Oct 2023 12:00:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-excel-sheet-name-in-sas/m-p/898904#M355294</guid>
      <dc:creator>varshabansal</dc:creator>
      <dc:date>2023-10-17T12:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting excel sheet name in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-excel-sheet-name-in-sas/m-p/898912#M355297</link>
      <description>&lt;P&gt;If it is an XLSX file you can read the XML file where the list of sheets is stored from inside of the XLSX file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See this old thread:&amp;nbsp;&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-import-second-sheet-from-Excel-workbook-in-to-SAS-without/td-p/669265" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/How-to-import-second-sheet-from-Excel-workbook-in-to-SAS-without/td-p/669265&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or even simpler use the code in this other thread:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Multiple-sheet-names/m-p/872092/highlight/true#M344531" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Multiple-sheet-names/m-p/872092/highlight/true#M344531&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data worksheets;
  infile "c:\downloads\book1.xlsx" zip member='xl/workbook.xml' recfm=n dsd dlm=' ';
  sheet_number+1;
  input @'&amp;lt;sheet name=' sheet_name :$32. @@;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Oct 2023 12:45:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-excel-sheet-name-in-sas/m-p/898912#M355297</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-10-17T12:45:04Z</dc:date>
    </item>
  </channel>
</rss>

