<?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: proc import sheet= in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-import-sheet/m-p/868091#M342877</link>
    <description>&lt;P&gt;yes the sheet="" option in proc import is meant to bring in a specific sheet for excel.&lt;/P&gt;&lt;P&gt;I think a macro would be your best bet if you have 50 workbooks.&lt;/P&gt;&lt;P&gt;I am assuming you are using xlsx format in the below example. I am also assuming the the name of your second sheet in your excel workbook is "Sheet 2". It could have a different name if you named it differently but the default is "Sheet 1", "Sheet 2", etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%maco get_ds(xlin=,dsout=);&lt;/P&gt;&lt;P&gt;proc import datafile="&amp;amp;xlin."&lt;/P&gt;&lt;P&gt;out=&amp;amp;dsout.&lt;/P&gt;&lt;P&gt;dbms=xlsx&amp;nbsp;&lt;/P&gt;&lt;P&gt;replace;&lt;/P&gt;&lt;P&gt;sheet="Sheet 2"&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend get_ds;&lt;/P&gt;&lt;P&gt;%get_ds(xlin=excel_workbook1.xlsx, dsout=outdata1);&lt;/P&gt;&lt;P&gt;%get_ds(xlin=excel_workbook2.xlsx, dsout=outdata2);&lt;/P&gt;&lt;P&gt;etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Apr 2023 21:20:18 GMT</pubDate>
    <dc:creator>Seadrago</dc:creator>
    <dc:date>2023-04-04T21:20:18Z</dc:date>
    <item>
      <title>proc import sheet=</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-import-sheet/m-p/868077#M342863</link>
      <description>&lt;P&gt;i have 50 xlsx excel workbooks, in a folder, i want to import the 2nd sheet of each excel and convert to sas datasets.&lt;/P&gt;&lt;P&gt;each of excel has different sheet name, but i know for each excel, i only need the 2nd sheet, is there a way to use sheet= "&amp;nbsp; &amp;nbsp;"&amp;nbsp; &amp;nbsp;to accomplish this?&lt;/P&gt;&lt;P&gt;thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ann&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 20:33:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-import-sheet/m-p/868077#M342863</guid>
      <dc:creator>yuhuanp</dc:creator>
      <dc:date>2023-04-04T20:33:21Z</dc:date>
    </item>
    <item>
      <title>Re: proc import sheet=</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-import-sheet/m-p/868091#M342877</link>
      <description>&lt;P&gt;yes the sheet="" option in proc import is meant to bring in a specific sheet for excel.&lt;/P&gt;&lt;P&gt;I think a macro would be your best bet if you have 50 workbooks.&lt;/P&gt;&lt;P&gt;I am assuming you are using xlsx format in the below example. I am also assuming the the name of your second sheet in your excel workbook is "Sheet 2". It could have a different name if you named it differently but the default is "Sheet 1", "Sheet 2", etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%maco get_ds(xlin=,dsout=);&lt;/P&gt;&lt;P&gt;proc import datafile="&amp;amp;xlin."&lt;/P&gt;&lt;P&gt;out=&amp;amp;dsout.&lt;/P&gt;&lt;P&gt;dbms=xlsx&amp;nbsp;&lt;/P&gt;&lt;P&gt;replace;&lt;/P&gt;&lt;P&gt;sheet="Sheet 2"&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend get_ds;&lt;/P&gt;&lt;P&gt;%get_ds(xlin=excel_workbook1.xlsx, dsout=outdata1);&lt;/P&gt;&lt;P&gt;%get_ds(xlin=excel_workbook2.xlsx, dsout=outdata2);&lt;/P&gt;&lt;P&gt;etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 21:20:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-import-sheet/m-p/868091#M342877</guid>
      <dc:creator>Seadrago</dc:creator>
      <dc:date>2023-04-04T21:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: proc import sheet=</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-import-sheet/m-p/868102#M342887</link>
      <description>&lt;P&gt;all 50 excel workbook the sheet2 have different names, the sheet name is not sheet2, it named by products, but i need to read the 2nd sheet from all 50 excels,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 21:57:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-import-sheet/m-p/868102#M342887</guid>
      <dc:creator>yuhuanp</dc:creator>
      <dc:date>2023-04-04T21:57:33Z</dc:date>
    </item>
    <item>
      <title>Re: proc import sheet=</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-import-sheet/m-p/868106#M342890</link>
      <description>&lt;P&gt;This&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;solution will probably help:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/import-multi-tab-excel-file-amp-export-with-tabs-in-same-order/m-p/830615" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/import-multi-tab-excel-file-amp-export-with-tabs-in-same-order/m-p/830615&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 22:25:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-import-sheet/m-p/868106#M342890</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-04-04T22:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: proc import sheet=</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-import-sheet/m-p/868217#M342947</link>
      <description>&lt;P&gt;Hi Ann,&lt;/P&gt;
&lt;P&gt;Here is a potential solution&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let myPath=&amp;lt;Path&amp;gt;;  *&amp;lt;--- Change this to point to your directory;
options validvarname=any;

%macro import_sheet2(p_xlsxWorkbook=, p_outDsName=);
	libname xl XLSX "&amp;amp;p_xlsxWorkbook";
	/* discover member (DATA) names */
	ods output members=work.members;
	proc datasets lib=xl;
	quit;
	
	/* Get the second sheet name */
	data _null_;
		set work.members(where=(num=2));
		call symput('l_sheetName',strip(name));
	run;
	/* %put &amp;amp;=l_sheetName; */&lt;BR /&gt;
	/* Generate the output data set from the second sheet */
	data &amp;amp;p_outDsName;
		SET xl.&amp;amp;l_sheetName;
	run;
	
	/* Clean-up */
	proc delete data=work.members; run;
	libname xl CLEAR;
%mend import_sheet2;

/* Find all xlsx workbooks in specified directory */
data _NULL_;
	length fref $8 filename $100 macroStmt $200;
	rc=filename(fref, "&amp;amp;myPath");
	if rc=0 then
	do;
		did=dopen(fref);
		rc=filename(fref);
	end;
	else
	do;
		length msg $200.;
		msg=sysmsg();
		put msg=;
		did=.;
	end;

	if did &amp;lt;=0 then putlog 'ERR' 'OR: Unable to open directory.';
	dnum=dnum(did);
	do i=1 to dnum;
		filename=dread(did, i);
		/* If this entry is a file, then process */
		fid=mopen(did, filename);
		if fid &amp;gt; 0 then
		do;
			/* Look for xlsx workbooks */
			if (scan(filename,2,'.') = 'xlsx') then
			do;
				macroStmt= '%import_sheet2(p_xlsxWorkbook=%str(&amp;amp;myPath/'||strip(filename)||'), p_outDsName='||scan(strip(filename),1,'.')||');';
				call execute (macroStmt);
			end;
		end;
	end;
	rc=dclose(did);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I didn't use Proc Import, instead I used the &lt;A title="XLSX Library Engine" href="https://blogs.sas.com/content/sasdummy/2015/05/20/using-libname-xlsx-to-read-and-write-excel-files/" target="_self"&gt;XLSX Library Engine&lt;/A&gt; that was added in SAS 9.4 M2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2023 13:00:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-import-sheet/m-p/868217#M342947</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2023-04-05T13:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: proc import sheet=</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-import-sheet/m-p/869625#M343493</link>
      <description>&lt;P&gt;thank you, the code works.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ann&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 16:59:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-import-sheet/m-p/869625#M343493</guid>
      <dc:creator>yuhuanp</dc:creator>
      <dc:date>2023-04-13T16:59:27Z</dc:date>
    </item>
  </channel>
</rss>

