<?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: Using Macro to Export to Excel in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-Export-to-Excel/m-p/357992#M84093</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22856"&gt;@SpaceMonkey&lt;/a&gt;:&amp;nbsp;Here's the current link to the SAS Note:&amp;nbsp;&lt;A href="http://support.sas.com/techsup/notes/v8/13/860.html" target="_blank"&gt;http://support.sas.com/techsup/notes/v8/13/860.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, that in itself should not cause problems with PROC IMPORT or producing the Excel file. &amp;nbsp;If you have SAS 9.4, I'd try DBMS=XLSX instead of DBMS=Excel -- you might be happier with the result. &amp;nbsp;If you can't get it working, I suggest that you create a different post with as much of the code and log that you can share.&lt;/P&gt;</description>
    <pubDate>Thu, 11 May 2017 16:52:20 GMT</pubDate>
    <dc:creator>ChrisHemedinger</dc:creator>
    <dc:date>2017-05-11T16:52:20Z</dc:date>
    <item>
      <title>Using Macro to Export to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-Export-to-Excel/m-p/52461#M11080</link>
      <description>I created a macro to cycle through all of the fields in a SAS database, created a proc freq, outputed them to a SAS dataset and now I want to export these to excel to send e-mail.  I want to put in a single excel file.  I tried to name the sheet the same name as the field name, but it is giving me an error because I don't have quotes around the sheet name.  Here is my code:&lt;BR /&gt;
&lt;BR /&gt;
libname LOSSDATA 'G:\NA\Corp\CORPACT\APPS\PRICING\Data Management\AgentsDataQuality\LOSS INFO';&lt;BR /&gt;
options mprint;&lt;BR /&gt;
** Frequency Test Macro **;&lt;BR /&gt;
%MACRO FREQ(DSET,FIELDNAME);&lt;BR /&gt;
	PROC FREQ DATA=&amp;amp;DSET NOPRINT;&lt;BR /&gt;
		TABLES &amp;amp;FIELDNAME / OUT=&amp;amp;FIELDNAME;&lt;BR /&gt;
	RUN;&lt;BR /&gt;
%MEND;&lt;BR /&gt;
** Export Macro **;&lt;BR /&gt;
%MACRO DQ_EXPORT(DSET,XLSHT);&lt;BR /&gt;
PROC EXPORT DATA= &amp;amp;DSET&lt;BR /&gt;
            OUTFILE= "G:\NA\Corp\CORPACT\APPS\PRICING\Data Management\AgentsDataQuality\Data Quality Tests\LossData\Frequency.xls" ;&lt;BR /&gt;
            DBMS=EXCEL REPLACE;&lt;BR /&gt;
     SHEET=&amp;amp;XLSHT; &lt;BR /&gt;
RUN;&lt;BR /&gt;
%MEND;&lt;BR /&gt;
&lt;BR /&gt;
** Macro for Looping through each field **;&lt;BR /&gt;
%MACRO FREQ_VAR_LIST(DSET);&lt;BR /&gt;
	PROC CONTENTS NOPRINT DATA=&amp;amp;DSET OUT=NAMETYPE(KEEP=NAME TYPE);&lt;BR /&gt;
	%LET DSID=%SYSFUNC(OPEN(NAMETYPE));&lt;BR /&gt;
	%LET NUM_OBS=%SYSFUNC(ATTRN(&amp;amp;DSID,NOBS));&lt;BR /&gt;
	%LET RC=%SYSFUNC(CLOSE(&amp;amp;DSID));&lt;BR /&gt;
&lt;BR /&gt;
	%LET DSID=%SYSFUNC(OPEN(&amp;amp;DSET,I));&lt;BR /&gt;
	%LET VARCOUNT=%SYSFUNC(ATTRN(&amp;amp;DSID,NVARS));&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
/* USe if statement if only some of the fields are required */&lt;BR /&gt;
&lt;BR /&gt;
	%DO I=1 %TO &amp;amp;VARCOUNT;&lt;BR /&gt;
		%LET VARNAME=%SYSFUNC(VARNAME(&amp;amp;DSID,&amp;amp;I));&lt;BR /&gt;
		%FREQ(&amp;amp;DSET,&amp;amp;VARNAME);&lt;BR /&gt;
		%LET SHTNAME=%QUOTE(&amp;amp;VARNAME);&lt;BR /&gt;
		%DQ_EXPORT(&amp;amp;VARNAME,&amp;amp;SHTNAME);&lt;BR /&gt;
	%END;&lt;BR /&gt;
	%LET RC=%SYSFUNC(CLOSE(&amp;amp;DSID));&lt;BR /&gt;
%MEND;		&lt;BR /&gt;
&lt;BR /&gt;
** Macro to run Test for all fields in a given dataset **;&lt;BR /&gt;
%FREQ_VAR_LIST(LOSSDATA.LOSSDATAFINAL);&lt;BR /&gt;
&lt;BR /&gt;
Here is the error I am getting:&lt;BR /&gt;
&lt;BR /&gt;
MPRINT(DQ_EXPORT):   PROC EXPORT DATA= A01_COMPANY OUTFILE=&lt;BR /&gt;
"G:\NA\Corp\CORPACT\APPS\PRICING\Data Management\AgentsDataQuality\Data Quality&lt;BR /&gt;
Tests\LossData\Frequency.xls" ;&lt;BR /&gt;
MPRINT(DQ_EXPORT):   AEXC;&lt;BR /&gt;
MPRINT(DQ_EXPORT):   DBMS=EXCEL REPLACE;&lt;BR /&gt;
NOTE: The previous statement has been deleted.&lt;BR /&gt;
MPRINT(DQ_EXPORT):   SHEET=A01_COMPANY;&lt;BR /&gt;
NOTE: The previous statement has been deleted.&lt;BR /&gt;
MPRINT(DQ_EXPORT):   RUN;&lt;BR /&gt;
NOTE: Line generated by the invoked macro "DQ_EXPORT".&lt;BR /&gt;
1                 DBMS=EXCEL REPLACE;      SHEET=&amp;amp;XLSHT; RUN;&lt;BR /&gt;
&lt;BR /&gt;
----&lt;BR /&gt;
&lt;BR /&gt;
180&lt;BR /&gt;
&lt;BR /&gt;
ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I am assuming it is because A01_COMPANY is not in quotes.  How do I get A01_COMPANY in quotes?</description>
      <pubDate>Tue, 07 Oct 2008 17:01:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-Export-to-Excel/m-p/52461#M11080</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-07T17:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro to Export to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-Export-to-Excel/m-p/52462#M11081</link>
      <description>To start, the DBMS= keyword should be part of the PROC EXPORT statement -- you have a semi-colon after the OUTFILE= parameter string.  There also appears to be some extraneous character string "AEXC" -- maybe not.  I believe that you can wrap your SHEET= parameter (resolved) in double-quotes, as well.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
SAS 9.2 PROC EXPORT DOC link:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/proc/59565/HTML/default/a000316288.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/59565/HTML/default/a000316288.htm&lt;/A&gt;</description>
      <pubDate>Tue, 07 Oct 2008 18:08:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-Export-to-Excel/m-p/52462#M11081</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2008-10-07T18:08:40Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro to Export to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-Export-to-Excel/m-p/52463#M11082</link>
      <description>It was the semicolon and not the quotes.  I am not sure why it is putting the AEXC in the MPRINT, but I am not doing anything to write it to the code.</description>
      <pubDate>Tue, 07 Oct 2008 19:55:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-Export-to-Excel/m-p/52463#M11082</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-07T19:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro to Export to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-Export-to-Excel/m-p/52464#M11083</link>
      <description>The AEXC is coming from MPRINT...see Usage Note 13860: AEXC returned by MPRINT when macros are used in PROC IMPORT for Excel</description>
      <pubDate>Mon, 06 Jul 2009 13:10:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-Export-to-Excel/m-p/52464#M11083</guid>
      <dc:creator>advoss</dc:creator>
      <dc:date>2009-07-06T13:10:36Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro to Export to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-Export-to-Excel/m-p/357720#M84017</link>
      <description>&lt;P&gt;Hi - I am currently having this problem. For some reason, when I use PROC EXPORT to Excel in a macro, I get the following line in the log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;MPRINT(EXPORT): AEXC;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;... and no Excel file is created.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I cannot find any usage note with number 13860 by searching the SAS site. Can someone please provide me with a link to a fix?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2017 01:40:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-Export-to-Excel/m-p/357720#M84017</guid>
      <dc:creator>SpaceMonkey</dc:creator>
      <dc:date>2017-05-11T01:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro to Export to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-Export-to-Excel/m-p/357992#M84093</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22856"&gt;@SpaceMonkey&lt;/a&gt;:&amp;nbsp;Here's the current link to the SAS Note:&amp;nbsp;&lt;A href="http://support.sas.com/techsup/notes/v8/13/860.html" target="_blank"&gt;http://support.sas.com/techsup/notes/v8/13/860.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, that in itself should not cause problems with PROC IMPORT or producing the Excel file. &amp;nbsp;If you have SAS 9.4, I'd try DBMS=XLSX instead of DBMS=Excel -- you might be happier with the result. &amp;nbsp;If you can't get it working, I suggest that you create a different post with as much of the code and log that you can share.&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2017 16:52:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-Export-to-Excel/m-p/357992#M84093</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2017-05-11T16:52:20Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro to Export to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-Export-to-Excel/m-p/397607#M96109</link>
      <description>Chris, is there a reason why DBMS=XLSX instead of DBMS=excelcs works? We were having a similar issue where the Excel file wasn't being created at all. We moved from a PC-SAS version of our code to a Server environment using EG and the same Proc Export code running in the Server SAS was not creating the Excel output file at all (nor throwing any errors). We had been told in the past to use the DBMS=excelcs option because of our setup and the version of MS office that we use. I was able to get the first sheet of the excel file created by using your suggestion. Any insights would be appreciated! Thanks, Lisa</description>
      <pubDate>Wed, 20 Sep 2017 20:47:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-Export-to-Excel/m-p/397607#M96109</guid>
      <dc:creator>LisaGawlick</dc:creator>
      <dc:date>2017-09-20T20:47:42Z</dc:date>
    </item>
  </channel>
</rss>

