<?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: Import Multiple Sheets from 1 Excel Workbook Using a %Do Loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Import-Multiple-Sheets-from-1-Excel-Workbook-Using-a-Do-Loop/m-p/625861#M184530</link>
    <description>&lt;P&gt;The letter i is never going to be less that the digit 1.&amp;nbsp; It is always going to be larger than the digit 9.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do you have that %IF at all?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;year1.&amp;lt;= 2018 %then %do;
  %do month = 1 %to 12;
    %let sheet=&amp;amp;year1.%sysfunc(putn(&amp;amp;month,z2));
proc import out= WORK.RS_&amp;amp;sheet datafile= Y1RS dbms=xlsx replace;
  sheet="&amp;amp;sheet";
  getnames=YES;
run;
  %end;
%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 19 Feb 2020 14:59:52 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-02-19T14:59:52Z</dc:date>
    <item>
      <title>Import Multiple Sheets from 1 Excel Workbook Using a %Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Multiple-Sheets-from-1-Excel-Workbook-Using-a-Do-Loop/m-p/625849#M184524</link>
      <description>&lt;P&gt;Good morning!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been testing out importing multiple sheets from 1 excel book by using a %Do loop within a macro. I want to import the sheets based upon their naming conventions in this case 201701, 201702, 201703,..... 201712. The issue that I am having is that for sheets 201701-201709, SAS is telling me that it cannot find the sheets. It does however import for sheets 201710 - 201712. Here is the code that I am using:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro importy1;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%if &amp;amp;year1. &amp;gt;2018 %THEN %DO;&lt;BR /&gt;%do i = 1 %to 4;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Proc Import out= WORK.RS_&amp;amp;Year1._Q&amp;amp;i DATAFILE= Y1RS DBMS=xlsx REPLACE;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SHEET="&amp;amp;Year1. Q&amp;amp;i";&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; GETNAMES=YES;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; RUN;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %END;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %END;&lt;BR /&gt;%else %if &amp;amp;year1.&amp;lt;= 2018 %then %do;&lt;BR /&gt;%do i = 1 %to 12;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %if i &amp;lt; 10 %then %do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Proc Import out= WORK.RS_&amp;amp;Year1.0&amp;amp;i DATAFILE= Y1RS DBMS=xlsx REPLACE;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SHEET="&amp;amp;Year1.0&amp;amp;i";&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; GETNAMES=YES;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; RUN;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %END&lt;BR /&gt;%ELSE %IF i &amp;gt; 9 %then %do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Proc Import out= WORK.RS_&amp;amp;Year1.&amp;amp;i DATAFILE= Y1RS DBMS=xlsx REPLACE;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SHEET="&amp;amp;Year1.&amp;amp;i";&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; GETNAMES=YES;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; RUN;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %end&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%MEND IMPORTy1;&lt;/P&gt;&lt;P&gt;%importy1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From what I can tell, the issue is that the 0 in the &amp;lt;10 statement is not being interpreted correctly, however I do not know how to correct this. If you could provide any insight on how to remedy this it would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 14:34:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Multiple-Sheets-from-1-Excel-Workbook-Using-a-Do-Loop/m-p/625849#M184524</guid>
      <dc:creator>ImASasMan</dc:creator>
      <dc:date>2020-02-19T14:34:36Z</dc:date>
    </item>
    <item>
      <title>Re: Import Multiple Sheets from 1 Excel Workbook Using a %Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Multiple-Sheets-from-1-Excel-Workbook-Using-a-Do-Loop/m-p/625852#M184526</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;The issue that I am having is that for sheets 201701-201709, SAS is telling me that it cannot find the sheets.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Then they are not there under that specific name in Excel, or the macro variables are not resolving as you expect. Perhaps the names in Excel are typed differently, and perhaps have spaces before or after the calendar date.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You might also want to turn on&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;options mprint;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;and run your code again and look in the log to see if the macro variables are begin created and resolved as you want them to be.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 14:43:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Multiple-Sheets-from-1-Excel-Workbook-Using-a-Do-Loop/m-p/625852#M184526</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-02-19T14:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: Import Multiple Sheets from 1 Excel Workbook Using a %Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Multiple-Sheets-from-1-Excel-Workbook-Using-a-Do-Loop/m-p/625854#M184528</link>
      <description>&lt;P&gt;You have to correctly reference your macro variable i. i is just text, &amp;amp;i is a reference to a macro variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do i = 1 %to 12;
  %if &amp;amp;i &amp;lt; 10 %then %do;
    proc import out=WORK.RS_&amp;amp;Year1.0&amp;amp;i DATAFILE=Y1RS dbms=xlsx replace;
    sheet="&amp;amp;Year1.0&amp;amp;i";
    getnames=yes;
    run;
  %end;
  %else %do;
    proc import out=WORK.RS_&amp;amp;Year1.&amp;amp;i DATAFILE=Y1RS dbms=xlsx replace;
    sheet="&amp;amp;Year1.&amp;amp;i";
    getnames=yes;
    run;
  %end;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 14:48:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Multiple-Sheets-from-1-Excel-Workbook-Using-a-Do-Loop/m-p/625854#M184528</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-02-19T14:48:26Z</dc:date>
    </item>
    <item>
      <title>Re: Import Multiple Sheets from 1 Excel Workbook Using a %Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Multiple-Sheets-from-1-Excel-Workbook-Using-a-Do-Loop/m-p/625861#M184530</link>
      <description>&lt;P&gt;The letter i is never going to be less that the digit 1.&amp;nbsp; It is always going to be larger than the digit 9.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do you have that %IF at all?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;year1.&amp;lt;= 2018 %then %do;
  %do month = 1 %to 12;
    %let sheet=&amp;amp;year1.%sysfunc(putn(&amp;amp;month,z2));
proc import out= WORK.RS_&amp;amp;sheet datafile= Y1RS dbms=xlsx replace;
  sheet="&amp;amp;sheet";
  getnames=YES;
run;
  %end;
%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Feb 2020 14:59:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Multiple-Sheets-from-1-Excel-Workbook-Using-a-Do-Loop/m-p/625861#M184530</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-19T14:59:52Z</dc:date>
    </item>
    <item>
      <title>Re: Import Multiple Sheets from 1 Excel Workbook Using a %Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Multiple-Sheets-from-1-Excel-Workbook-Using-a-Do-Loop/m-p/625872#M184533</link>
      <description>&lt;P&gt;Hi !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's always good to get to the bottom of a coding challenge but sometimes you just need an alternative solution. Depending on the version of SAS and or EG you are using you could try the LIBNAME engine XLSX. One line of code gets you all the worksheets (tabs) in a workbook. I created a dummy workbook with three tabs named 201701, 201702, 201703 with some regional salesperson data. With this simple libname, I have a SAS Lib (WRKBK) with all three tabs as datasets named 201701, 201702, 201703. (Keep in mind those names are not "good" dataset names because a sas dataset should not start with a numeric.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I realize this doesn't solve the original macro question, but if you simply need to get the data into SAS to work with, this may be a quick alternative.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAS EG 8.1 code and lib" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/36235i327558ECAA34BE48/image-size/large?v=v2&amp;amp;px=999" role="button" title="Solution 1.jpg" alt="SAS EG 8.1 code and lib" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;SAS EG 8.1 code and lib&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname wrkbk xlsx '\\denfilera\risk-mgmt\erm\personal folders\noble\libname_excel.xlsx';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Feb 2020 15:33:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Multiple-Sheets-from-1-Excel-Workbook-Using-a-Do-Loop/m-p/625872#M184533</guid>
      <dc:creator>PerryNoble</dc:creator>
      <dc:date>2020-02-19T15:33:37Z</dc:date>
    </item>
    <item>
      <title>Re: Import Multiple Sheets from 1 Excel Workbook Using a %Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Multiple-Sheets-from-1-Excel-Workbook-Using-a-Do-Loop/m-p/625891#M184540</link>
      <description>&lt;P&gt;Adding on to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22084"&gt;@PerryNoble&lt;/a&gt;&amp;nbsp; solution, libname + PROC COPY will copy all data sets in for you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Worth a try at least.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname wrkbk xlsx 'path to xlsx file';


proc copy in=wrkbk out=work;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Feb 2020 16:34:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Multiple-Sheets-from-1-Excel-Workbook-Using-a-Do-Loop/m-p/625891#M184540</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-19T16:34:02Z</dc:date>
    </item>
  </channel>
</rss>

