<?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 PROC IMPORT....multiple sheets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-multiple-sheets/m-p/391857#M94205</link>
    <description>&lt;P&gt;&lt;SPAN&gt;&lt;FONT size="3"&gt;&amp;nbsp;I’m trying to import a bunch of excel files (~30 odd files, with over 10 tabs in each.) into SAS using proc import , and I’d then append them into a single SAS file for my analysis. However, I’m facing a few challenges in putting this entire import into a SAS macro because the work sheet names in each of the excel files are different.All of them have the same 2-3 words at the beginning, but can have very different names towards the end. &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;FONT size="3"&gt;I was wondering if there’s a work around for this? Can we use some function/ operation similar to substr where I can select the worksheets/tabs that start with “Cost Cg PRCH” and then import them?&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;FONT size="3"&gt;Please do let me know if&amp;nbsp;we can thing about an alternative.&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;FONT size="3"&gt;Thanks a lot.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;FONT size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Times New Roman" size="3"&gt;&lt;IMG width="194" height="166" border="0" /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;FONT size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Times New Roman" size="3"&gt;&lt;IMG width="274" height="93" border="0" /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 30 Aug 2017 14:30:20 GMT</pubDate>
    <dc:creator>Debi</dc:creator>
    <dc:date>2017-08-30T14:30:20Z</dc:date>
    <item>
      <title>PROC IMPORT....multiple sheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-multiple-sheets/m-p/391857#M94205</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&lt;FONT size="3"&gt;&amp;nbsp;I’m trying to import a bunch of excel files (~30 odd files, with over 10 tabs in each.) into SAS using proc import , and I’d then append them into a single SAS file for my analysis. However, I’m facing a few challenges in putting this entire import into a SAS macro because the work sheet names in each of the excel files are different.All of them have the same 2-3 words at the beginning, but can have very different names towards the end. &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;FONT size="3"&gt;I was wondering if there’s a work around for this? Can we use some function/ operation similar to substr where I can select the worksheets/tabs that start with “Cost Cg PRCH” and then import them?&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;FONT size="3"&gt;Please do let me know if&amp;nbsp;we can thing about an alternative.&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;FONT size="3"&gt;Thanks a lot.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;FONT size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Times New Roman" size="3"&gt;&lt;IMG width="194" height="166" border="0" /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;FONT size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Times New Roman" size="3"&gt;&lt;IMG width="274" height="93" border="0" /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 14:30:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-multiple-sheets/m-p/391857#M94205</guid>
      <dc:creator>Debi</dc:creator>
      <dc:date>2017-08-30T14:30:20Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IMPORT....multiple sheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-multiple-sheets/m-p/391863#M94206</link>
      <description>&lt;P&gt;Assuming the latest version of SAS you can try this method:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname myFiles XLSX 'path to my excel file.xlsx';

proc copy in=myFiles out=WORK;
run;quit;

libname myFiles;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Aug 2017 14:39:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-multiple-sheets/m-p/391863#M94206</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-30T14:39:46Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IMPORT....multiple sheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-multiple-sheets/m-p/392012#M94247</link>
      <description>&lt;P&gt;I suggest taking a close look at all of the datasets created from multiple Excel sheets. Probability approaches unity that at least one variable will have a different data type or length that will cause issues when appending the data.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 20:11:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-multiple-sheets/m-p/392012#M94247</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-08-30T20:11:55Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IMPORT....multiple sheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-multiple-sheets/m-p/392122#M94294</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your reply. But ,I am in doubt how it will help me in getting conditional sheets of the excel . So, If I explain it in more details I have 2 requirements::&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. I have to import multiple excel files.&lt;/P&gt;&lt;P&gt;2. Each excel file have multiple sheets with diffeent names . But, all the files have some sheets having names starting with "Cost Cg PRCH" . I want to import only those sheets of all the excel files . Per my understanding some filter or conditional statement needed to take the specific sheets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please suggest.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2017 08:08:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-multiple-sheets/m-p/392122#M94294</guid>
      <dc:creator>Debi</dc:creator>
      <dc:date>2017-08-31T08:08:19Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IMPORT....multiple sheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-multiple-sheets/m-p/392225#M94346</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/63123"&gt;@Debi&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Per my understanding some filter or conditional statement needed to take the specific sheets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please suggest.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Import all the worksheets and delete what you don't want instead.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarding importing multiple files you're likely going to need to turn that into a macro or copy and paste it a few times, depending on what you're comfortable with.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2017 14:33:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-multiple-sheets/m-p/392225#M94346</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-31T14:33:10Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IMPORT....multiple sheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-multiple-sheets/m-p/392239#M94354</link>
      <description>&lt;P&gt;There are many posts on this sites about how to deal with reading multiple files and/or multiple sheets. Just combine the techniques.&lt;/P&gt;
&lt;P&gt;So first get the list of files you need to read. &amp;nbsp;If you do not have the list then for me the easist is to use operating system command to get the filenames into a dataset, but if your SAS installation doesn't allow using PIPE engine there are SAS functions that can do that also.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* %let path=/path/to/excel/files; */
%let path=c:\path\to\excel\files ;
data files ;
   /* infile "cd &amp;amp;path ; ls -d *.xlsx" pipe truncover ; */
   infile "dir /b &amp;amp;path\*.xlsx" pipe truncover ;
   input filename $256. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you have the list of filenames then you can assign a libref to each one. Might be easiest to use the LIBNAME() function to do that, but you could also use some type of code generatation technique (macros, call execute(), or combination of PUT and %INCLUDE).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data librefs;
  length libref $8 ;
  set files ;
  libref = 'XLSX' || put(_n_,Z4.);
  rc = libname(libref,"&amp;amp;path/"||filename,'xlsx');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can query the metadata about what members exists in the libraries you created.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint ;
  select catx('.',libname,nliteral(memname))
    into :memlist separated by ' ' 
    from dictionary.members
    where libname like 'XLSX%'
      and memname like 'COST CG PRCH%'
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And then use the list of member names in your data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set &amp;amp;memlist ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But as others have pointed out that unless there are strict controls on the generation of these EXCEL sheets the odds are almost 100% that when&amp;nbsp;you try to read from multiple EXCEL sheets you will get conflicting variable lengths ($10 vs $20 for example) or even conflicting variable types (num vs char) or names (VisitDate vs VisDT). &amp;nbsp;You can analyze other metadata about the sheets to see if there are conflicts and adapt your combination step(s) to adjust, if possible, or at least report on the conflicts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2017 15:04:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-multiple-sheets/m-p/392239#M94354</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-08-31T15:04:02Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IMPORT....multiple sheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-multiple-sheets/m-p/485908#M126306</link>
      <description>&lt;P&gt;This is genius! I'm new to SAS programming and find macros a bit overwhelming. This makes it very easy.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Aug 2018 18:37:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-multiple-sheets/m-p/485908#M126306</guid>
      <dc:creator>KayRee</dc:creator>
      <dc:date>2018-08-10T18:37:30Z</dc:date>
    </item>
  </channel>
</rss>

