<?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 Importing multiple excel sheets with a macro loop in SAS Data Science</title>
    <link>https://communities.sas.com/t5/SAS-Data-Science/Importing-multiple-excel-sheets-with-a-macro-loop/m-p/153822#M9373</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey there,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I've been spinning my wheels at this for way too long that I feel like there must be a better way.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have an excel workbook that I have assigned a libname and I would like to do formatting on the sheets which are labeled in a way that I thought would be conducive to set up a loop. Unfortunately the fact that the sheets are named with single quotes around them makes referencing a macro variable difficult.&amp;nbsp; This is my closest attempt but the quotes get lost in the call symputx statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;libname &amp;amp;facil_export. "&amp;amp;path.\&amp;amp;facil_export._clean.xlsx";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro import_loop;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%do i = 1 %to &amp;amp;periods.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let sheet = "Period (&amp;amp;i.)$";&lt;/P&gt;&lt;P&gt;%let the_n = n;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;format sheet_v2 $15.;&lt;/P&gt;&lt;P&gt;sheet_v2 = tranwrd(&amp;amp;sheet.,'"',"'");&lt;/P&gt;&lt;P&gt;call symputx('sheet_final', sheet_v2);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data &amp;amp;facil_export._&amp;amp;i.; set &amp;amp;facil_export..&amp;amp;sheet_final.&amp;amp;the_n.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%import_loop;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 28 Jan 2014 00:43:30 GMT</pubDate>
    <dc:creator>philfoot123</dc:creator>
    <dc:date>2014-01-28T00:43:30Z</dc:date>
    <item>
      <title>Importing multiple excel sheets with a macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Importing-multiple-excel-sheets-with-a-macro-loop/m-p/153822#M9373</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey there,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I've been spinning my wheels at this for way too long that I feel like there must be a better way.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have an excel workbook that I have assigned a libname and I would like to do formatting on the sheets which are labeled in a way that I thought would be conducive to set up a loop. Unfortunately the fact that the sheets are named with single quotes around them makes referencing a macro variable difficult.&amp;nbsp; This is my closest attempt but the quotes get lost in the call symputx statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;libname &amp;amp;facil_export. "&amp;amp;path.\&amp;amp;facil_export._clean.xlsx";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro import_loop;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%do i = 1 %to &amp;amp;periods.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let sheet = "Period (&amp;amp;i.)$";&lt;/P&gt;&lt;P&gt;%let the_n = n;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;format sheet_v2 $15.;&lt;/P&gt;&lt;P&gt;sheet_v2 = tranwrd(&amp;amp;sheet.,'"',"'");&lt;/P&gt;&lt;P&gt;call symputx('sheet_final', sheet_v2);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data &amp;amp;facil_export._&amp;amp;i.; set &amp;amp;facil_export..&amp;amp;sheet_final.&amp;amp;the_n.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%import_loop;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Jan 2014 00:43:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Importing-multiple-excel-sheets-with-a-macro-loop/m-p/153822#M9373</guid>
      <dc:creator>philfoot123</dc:creator>
      <dc:date>2014-01-28T00:43:30Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple excel sheets with a macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Importing-multiple-excel-sheets-with-a-macro-loop/m-p/153823#M9374</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I do not understand the problem.&amp;nbsp; What SAS code are you trying to generate?&lt;/P&gt;&lt;P&gt;Note that name literals (and other SAS literals) can use double quotes or single quotes.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 12pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 12pt;"&gt;%let i=5 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 12pt;"&gt;%put "Period (&amp;amp;i)$"n;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that you can use single quotes around macro variables if they are not the outer quotes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 12pt;"&gt;%let i=5 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 12pt;"&gt;%put "'Period (&amp;amp;i)$'"n;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 12pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Jan 2014 02:12:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Importing-multiple-excel-sheets-with-a-macro-loop/m-p/153823#M9374</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-01-28T02:12:07Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple excel sheets with a macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Importing-multiple-excel-sheets-with-a-macro-loop/m-p/153824#M9375</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey Tom,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The issue I'm having is that, using the libname engine - a excel sheet needs to have the single quotes around it to be referenced and since i'm trying to reference many sheets i'm using a macro loop.&amp;nbsp; I haven't been able to figure out how I can output the sheet name (ie - 'Period (1)'n Period (2)'n etc.) with the macro do-loop variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried both of your examples above but with no luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Jan 2014 18:19:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Importing-multiple-excel-sheets-with-a-macro-loop/m-p/153824#M9375</guid>
      <dc:creator>philfoot123</dc:creator>
      <dc:date>2014-01-28T18:19:42Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple excel sheets with a macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Importing-multiple-excel-sheets-with-a-macro-loop/m-p/153825#M9376</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;First get it to work typing them by hand.&amp;nbsp; &lt;/P&gt;&lt;P&gt;If the code you posted generates the string you want, but it does not work in might be a macro quoting issue.&amp;nbsp; Try either generating the concatenated text to a new macro variable or wrapping it in a %unquote() function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;set %unquote(&amp;amp;facil_export..&amp;amp;sheet_final.&amp;amp;the_n.) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Jan 2014 21:40:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Importing-multiple-excel-sheets-with-a-macro-loop/m-p/153825#M9376</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-01-28T21:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple excel sheets with a macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Importing-multiple-excel-sheets-with-a-macro-loop/m-p/153826#M9377</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have a look at my example that uses dictionary tables and PROC DATASETS rather than macro looping. It does rely on the Excel tabs conforming to SAS dataset naming conventions though:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" href="https://communities.sas.com/message/170166#170166"&gt;https://communities.sas.com/message/170166#170166&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Jan 2014 22:48:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Importing-multiple-excel-sheets-with-a-macro-loop/m-p/153826#M9377</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2014-01-28T22:48:03Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple excel sheets with a macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Importing-multiple-excel-sheets-with-a-macro-loop/m-p/153827#M9378</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you sure of your sheet names?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 12pt;"&gt;8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; options validvarname=any;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 12pt;"&gt;9&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 12pt;"&gt;10&amp;nbsp;&amp;nbsp;&amp;nbsp; %let i=1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 12pt;"&gt;11&amp;nbsp;&amp;nbsp;&amp;nbsp; data x&amp;amp;i;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 12pt;"&gt;12&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set xx."'Part (&amp;amp;i)$'"n ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 12pt;"&gt;13&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 12pt;"&gt;NOTE: There were 31 observations read from the data set XX."'Part (1)$'"n.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 12pt;"&gt;NOTE: The data set WORK.X1 has 31 observations and 4 variables.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Jan 2014 22:59:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Importing-multiple-excel-sheets-with-a-macro-loop/m-p/153827#M9378</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-01-28T22:59:42Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple excel sheets with a macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Importing-multiple-excel-sheets-with-a-macro-loop/m-p/153828#M9379</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks guys - I ended up going a different route and utilizing the sashelp.vstabvw table to create an index of the sheet names.&amp;nbsp; This paper outlines the technique - I appreciate the feedback though ! &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/sugi31/034-31.pdf" title="http://www2.sas.com/proceedings/sugi31/034-31.pdf"&gt;http://www2.sas.com/proceedings/sugi31/034-31.pdf&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Jan 2014 02:26:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Importing-multiple-excel-sheets-with-a-macro-loop/m-p/153828#M9379</guid>
      <dc:creator>philfoot123</dc:creator>
      <dc:date>2014-01-29T02:26:38Z</dc:date>
    </item>
  </channel>
</rss>

