<?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: macro error to import multiple excel sheets and add column variables in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-error-to-import-multiple-excel-sheets-and-add-column/m-p/164309#M12645</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Macro variable references will not be resolved inside of single quotes.&amp;nbsp; Use the double quote character instead.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff; font-size: 12pt;"&gt;Sheet= "&amp;amp;sheet"&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 11 Feb 2015 20:52:26 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2015-02-11T20:52:26Z</dc:date>
    <item>
      <title>macro error to import multiple excel sheets and add column variables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-error-to-import-multiple-excel-sheets-and-add-column/m-p/164308#M12644</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello, I have to import 30+ excel workbooks into SAS for analysis.&amp;nbsp; Each workbook has the same number of tabs with the same format.&amp;nbsp; There are 12 tabs per workbook, with the first tab being INSTRUCTIONS.&amp;nbsp; I need to import tabs 2-12 of each workbook.&amp;nbsp; Here is my attempt at a macro: ************************************************* %macro pim(sheet); Proc Import Out=test Datafile='/home/risk/Consumer Heatmap 2015.xls' DBMS=xls Replace; Sheet= '&amp;amp;sheet'; Datarow=10; Run; %mend pim; %pim(Heat Map Channel Agnostic); %pim(ATM); ************************************************ When I run the above macro, I get this error.&amp;nbsp; Note the two // before the word Consumer.&amp;nbsp; I have triple checked and retyped the file path to eliminate an possible space but still get the same error. OTE: Writing RTF Body file: EGRTF 30&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FILENAME EGSR TEMP; 31&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR 32&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; STYLE=HtmlBlue 33&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; STYLESHEET=(URL="file:///C:/Program%20Files/SASHome/SASEnterpriseGuide/6.1/Styles/HtmlBlue.css") 34&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NOGTITLE 35&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NOGFOOTNOTE 36&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GPATH=&amp;amp;sasworklocation 37&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ENCODING=UTF8 38&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; options(rolap="on") 39&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR 40&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 41&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GOPTIONS ACCESSIBLE; 42&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %pim('Heat Map Channel Agnostic'); Requested Sheet Name not found on Excel -&amp;gt; /home/risk//Consumer Heatmap 2015.xls Requested Input File Is Invalid ERROR: Import unsuccessful.&amp;nbsp; See SAS Log for details. Few questions: 1.&amp;nbsp; Any idea on why SAS sees two // instead of one? 2.&amp;nbsp; Since I am importing multiple sheets, when using proc import, is it possible: a.&amp;nbsp; have the multiple sheets imported as one dataset per workbook?&amp;nbsp; For example, workbook1 will have all its sheet in dataset1, workbook2 will be in dataset2, etc? b.&amp;nbsp; to add a column to indicate the channel (i.e. Agnostic, ATM, etc)?&amp;nbsp; Or do I have to do this as another datastep?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2015 20:27:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-error-to-import-multiple-excel-sheets-and-add-column/m-p/164308#M12644</guid>
      <dc:creator>jen123</dc:creator>
      <dc:date>2015-02-11T20:27:45Z</dc:date>
    </item>
    <item>
      <title>Re: macro error to import multiple excel sheets and add column variables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-error-to-import-multiple-excel-sheets-and-add-column/m-p/164309#M12645</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Macro variable references will not be resolved inside of single quotes.&amp;nbsp; Use the double quote character instead.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff; font-size: 12pt;"&gt;Sheet= "&amp;amp;sheet"&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2015 20:52:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-error-to-import-multiple-excel-sheets-and-add-column/m-p/164309#M12645</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-02-11T20:52:26Z</dc:date>
    </item>
    <item>
      <title>Re: macro error to import multiple excel sheets and add column variables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-error-to-import-multiple-excel-sheets-and-add-column/m-p/164310#M12646</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Tom - THANK YOU!!!&amp;nbsp; The double quote worked.&amp;nbsp; I should've known better.&amp;nbsp; Any chance you know the answers to the last part of my original post?&amp;nbsp; I copy/paste it below.&amp;nbsp; Do I need to post the question as a new discussion?&amp;nbsp; Thanks!!! ************************ Few questions: 1.&amp;nbsp; Any idea on why SAS sees two // instead of one? 2.&amp;nbsp; Since I am importing multiple sheets, when using proc import, is it possible: a.&amp;nbsp; have the multiple sheets imported as one dataset per workbook?&amp;nbsp; For example, workbook1 will have all its sheet in dataset1, workbook2 will be in dataset2, etc? b.&amp;nbsp; to add a column to indicate the channel (i.e. Agnostic, ATM, etc)?&amp;nbsp; Or do I have to do this as another datastep?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2015 21:21:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-error-to-import-multiple-excel-sheets-and-add-column/m-p/164310#M12646</guid>
      <dc:creator>jen123</dc:creator>
      <dc:date>2015-02-11T21:21:00Z</dc:date>
    </item>
    <item>
      <title>Re: macro error to import multiple excel sheets and add column variables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-error-to-import-multiple-excel-sheets-and-add-column/m-p/164311#M12647</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Its a bit hard to follow your code in the current format, but it looks like a proc import. &lt;/P&gt;&lt;P&gt;That means you will have to create a new column in a new data step/sql step to add the column. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can add it at the end of the macro, assuming you pass in a sheet name. If all your OUT in proc import have the name test they will overwrite each other.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro pim(sheet);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*proc import code;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;set test;&lt;/P&gt;&lt;P&gt;Sheet="&amp;amp;Sheet";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2015 23:42:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-error-to-import-multiple-excel-sheets-and-add-column/m-p/164311#M12647</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-02-11T23:42:46Z</dc:date>
    </item>
    <item>
      <title>Re: macro error to import multiple excel sheets and add column variables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-error-to-import-multiple-excel-sheets-and-add-column/m-p/164312#M12648</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't know why my post looked like that.&amp;nbsp; I'm going to try to post my macro here again: ************************************************* %macro pim(sheet); Proc Import Out=test Datafile='/home/risk/Consumer Heatmap 2015.xls' DBMS=xls Replace; Sheet= "&amp;amp;sheet"; Datarow=10; Run; %mend pim; %pim(Heat Map Channel Agnostic); %pim(ATM); ************************************************ I am sorry I do not fully understand your response Reeza.&amp;nbsp; I am a beginner at SAS (or even coding). I understand if I use "Out=test", each import will overwrite the previous.&amp;nbsp; What do I need to do so that each import (i.e. Agnostic, ATM, etc) does not overwrite one another and that I can combine them all into on dataset?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Feb 2015 02:48:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-error-to-import-multiple-excel-sheets-and-add-column/m-p/164312#M12648</guid>
      <dc:creator>jen123</dc:creator>
      <dc:date>2015-02-12T02:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: macro error to import multiple excel sheets and add column variables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-error-to-import-multiple-excel-sheets-and-add-column/m-p/164313#M12649</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A few points.&lt;/P&gt;&lt;P&gt;1) Copy and paste the program in WORD or some other editor and then copy and paste into the forum.&amp;nbsp; It should preserve the formatting better.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2) Can you use the LIBNAME method to access your XLS files?&amp;nbsp; It would make it much easier to copy all of the sheets without having to type the names one by one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3) Unless the number of sheets is really large (over 20-30) you are probably much better off as a novice to just use "wallpaper code".&amp;nbsp; That is figure out how to import one sheet.&amp;nbsp; Copy the code and change the sheet name and the output data set name.&amp;nbsp; Repeat until you have imported all of the sheets. Modern (for example any thing written after 1979) make it really easy to duplicate code lines.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;4) Once you have a number of data sets you can easily combine them by using a data step.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc import out=sheet1 datafile='.....' replace ; sheet="...."; run;&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;proc import out=sheet14 datafile='.....' replace; sheet="...."; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set sheet1-sheet14 ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Feb 2015 03:43:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-error-to-import-multiple-excel-sheets-and-add-column/m-p/164313#M12649</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-02-12T03:43:52Z</dc:date>
    </item>
  </channel>
</rss>

