<?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 Excel Save As Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Excel-Save-As-Macro/m-p/90768#M19209</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; macroHello&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have written a SAS macro to open an excel spreadsheet using dde. I've also got one to do a "save as"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-size: 10pt; font-family: 'Courier New';"&gt;%macro&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt; excelsaveas(ifile, ilength);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;filename cmds dde &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: purple; font-family: 'Courier New';"&gt;'excel|system'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt; file cmds;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp; put &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: purple; font-family: 'Courier New';"&gt;'[error(false)]'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: green; font-family: 'Courier New';"&gt;*prevent excel asking "are you sure?";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp; put &amp;amp;ifile;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp; x=sleep(&amp;amp;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: teal; font-family: 'Courier New';"&gt;ilength.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp; put &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: purple; font-family: 'Courier New';"&gt;"[QUIT()]"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp; x=sleep(&amp;amp;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: teal; font-family: 'Courier New';"&gt;ilength.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-size: 10pt; font-family: 'Courier New';"&gt;%mend&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;I can call the macro like this&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;%&lt;STRONG&gt;&lt;EM&gt;excelsaveas&lt;/EM&gt;&lt;/STRONG&gt;(&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: blue; font-family: 'Courier New';"&gt;%str&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;('[SAVE.AS("C:\TEMP\test2.xls")]'), &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10pt; font-family: 'Courier New';"&gt;5&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first parameter is the save-as name and location. The second parameter is how many seconds SAS should sleep for before continuing, because SAS doesn't know when the execution of the save-as command has been completed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This works fine, however what I want to do is include a macro variable in the save-as name of the spreadsheet. This will allow me to save the spreadsheet with the date in the name, which would be really useful! However, I can't find any combination of double/single quotes or quoting functions that work. I've also tried rewriting the macro in various ways, but SAS always comes back with an error.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Has anyone done something like this before, is it possible, and if so how?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 10 Oct 2012 09:04:09 GMT</pubDate>
    <dc:creator>JamesNewcombe</dc:creator>
    <dc:date>2012-10-10T09:04:09Z</dc:date>
    <item>
      <title>Excel Save As Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excel-Save-As-Macro/m-p/90768#M19209</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; macroHello&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have written a SAS macro to open an excel spreadsheet using dde. I've also got one to do a "save as"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-size: 10pt; font-family: 'Courier New';"&gt;%macro&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt; excelsaveas(ifile, ilength);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;filename cmds dde &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: purple; font-family: 'Courier New';"&gt;'excel|system'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt; file cmds;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp; put &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: purple; font-family: 'Courier New';"&gt;'[error(false)]'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: green; font-family: 'Courier New';"&gt;*prevent excel asking "are you sure?";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp; put &amp;amp;ifile;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp; x=sleep(&amp;amp;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: teal; font-family: 'Courier New';"&gt;ilength.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp; put &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: purple; font-family: 'Courier New';"&gt;"[QUIT()]"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp; x=sleep(&amp;amp;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: teal; font-family: 'Courier New';"&gt;ilength.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-size: 10pt; font-family: 'Courier New';"&gt;%mend&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;I can call the macro like this&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;%&lt;STRONG&gt;&lt;EM&gt;excelsaveas&lt;/EM&gt;&lt;/STRONG&gt;(&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: blue; font-family: 'Courier New';"&gt;%str&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;('[SAVE.AS("C:\TEMP\test2.xls")]'), &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10pt; font-family: 'Courier New';"&gt;5&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first parameter is the save-as name and location. The second parameter is how many seconds SAS should sleep for before continuing, because SAS doesn't know when the execution of the save-as command has been completed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This works fine, however what I want to do is include a macro variable in the save-as name of the spreadsheet. This will allow me to save the spreadsheet with the date in the name, which would be really useful! However, I can't find any combination of double/single quotes or quoting functions that work. I've also tried rewriting the macro in various ways, but SAS always comes back with an error.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Has anyone done something like this before, is it possible, and if so how?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Oct 2012 09:04:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excel-Save-As-Macro/m-p/90768#M19209</guid>
      <dc:creator>JamesNewcombe</dc:creator>
      <dc:date>2012-10-10T09:04:09Z</dc:date>
    </item>
    <item>
      <title>Re: Excel Save As Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excel-Save-As-Macro/m-p/90769#M19210</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you would be much better off trying to build the save as part in the macro instead of as a parameter. The various quoting and unquoting functions in SAS will be a nightmare with that whole statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I solved a similar bit with following: (xlsx not xls but logic is the same)&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;SPAN lang="EN"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;put %unquote(%str(%'[SAVE.AS("&amp;amp;name..xlsx",51)]%'));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your macro call using just the path and file name&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%excelsave(%str(c:\temp\test2.xls),5);&lt;/P&gt;&lt;P&gt;with line instead fo put &amp;amp;ifile&lt;/P&gt;&lt;P&gt;put %unquote(%str(%'[SAVE.AS("&amp;amp;ifile",51)]%'));&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;SPAN lang="EN"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Oct 2012 14:52:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excel-Save-As-Macro/m-p/90769#M19210</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2012-10-10T14:52:07Z</dc:date>
    </item>
  </channel>
</rss>

