<?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 to export dataset to Excel with filename var in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-dataset-to-Excel-with-filename-var/m-p/71244#M15412</link>
    <description>Enhancement?  The use of %SYSFUNC opens up the use of DATA STEP functions within the macro language.  From the original OP, the function used CONCAT was invalid and unnecessary within the macro language.  The CAT function coded within a %SYSFUNC( ) would have worked fine or the use of macro variables as was demonstrated.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
    <pubDate>Thu, 17 Sep 2009 12:24:51 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2009-09-17T12:24:51Z</dc:date>
    <item>
      <title>Macro to export dataset to Excel with filename var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-dataset-to-Excel-with-filename-var/m-p/71237#M15405</link>
      <description>Hello -- has anyone used a macro to export a dataset to Excel, using the export filename as a variable? I've started code below but then get this error, &lt;BR /&gt;
&lt;BR /&gt;
"170! ".xls"&lt;BR /&gt;
          -&lt;BR /&gt;
          49&lt;BR /&gt;
170! )&lt;BR /&gt;
NOTE 49-169: The meaning of an identifier after a quoted string may change in a future SAS&lt;BR /&gt;
             release.  Inserting white space between a quoted string and the succeeding&lt;BR /&gt;
             identifier is recommended&lt;BR /&gt;
---------------------------------------------------------------------&lt;BR /&gt;
&lt;BR /&gt;
%let yrmon = '200909';&lt;BR /&gt;
%let dt = '091409';&lt;BR /&gt;
%macro exportxl;&lt;BR /&gt;
PROC EXPORT DATA= WORK.YRMON_ALL2SUM &lt;BR /&gt;
            OUTFILE= concat("I:\1 Commissions\PPA\Audit\",  &amp;amp;yrmon,  "\test2_" , &amp;amp;dt  , ".xls") &lt;BR /&gt;
            DBMS=EXCEL REPLACE;&lt;BR /&gt;
     SHEET="test2"; &lt;BR /&gt;
RUN;&lt;BR /&gt;
%mend exportxl;</description>
      <pubDate>Mon, 14 Sep 2009 14:54:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-dataset-to-Excel-with-filename-var/m-p/71237#M15405</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-09-14T14:54:10Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to export dataset to Excel with filename var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-dataset-to-Excel-with-filename-var/m-p/71238#M15406</link>
      <description>Hello.&lt;BR /&gt;
&lt;BR /&gt;
Try this instead:&lt;BR /&gt;
&lt;BR /&gt;
%let yrmon = '200909';&lt;BR /&gt;
%let dt = '091409';&lt;BR /&gt;
%let OUTFILE=I:\1 Commissions\PPA\Audit\&amp;amp;YRMON\test2_&amp;amp;DT..xls;&lt;BR /&gt;
%macro exportxl;&lt;BR /&gt;
PROC EXPORT DATA= WORK.YRMON_ALL2SUM&lt;BR /&gt;
OUTFILE= "&amp;amp;OUTFILE"&lt;BR /&gt;
DBMS=EXCEL REPLACE;&lt;BR /&gt;
SHEET="test2";&lt;BR /&gt;
RUN;&lt;BR /&gt;
%mend exportxl; &lt;BR /&gt;
&lt;BR /&gt;
You cannot reference the use of any functions (beside macro ones) for the procedure arguments. So in the example above, the OUTFILE expression is build into a macro var before the actual procedure call.&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;</description>
      <pubDate>Mon, 14 Sep 2009 16:04:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-dataset-to-Excel-with-filename-var/m-p/71238#M15406</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-09-14T16:04:43Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to export dataset to Excel with filename var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-dataset-to-Excel-with-filename-var/m-p/71239#M15407</link>
      <description>Thanks Daniel. Does anyone know if there is an enhancement being planned to be able to use functions in procedure arguments? If not, is there somewhere I can submit an enhancement request?</description>
      <pubDate>Mon, 14 Sep 2009 16:15:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-dataset-to-Excel-with-filename-var/m-p/71239#M15407</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-09-14T16:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to export dataset to Excel with filename var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-dataset-to-Excel-with-filename-var/m-p/71240#M15408</link>
      <description>P.S.  The other approach I tried was to set the filename value in the %let statement as you have indicated, but concatenated with a nested macro variable using ||. That approach didn't work, such as the following -- perhaps for similar reason that the concat errored out?&lt;BR /&gt;
______________________________________&lt;BR /&gt;
%let yrmon = '2009_09';&lt;BR /&gt;
%let filenm = 'I:\1 Commissions\PPA\Audit\' ||  &amp;amp;yrmon || '\insues_091409.xls';&lt;BR /&gt;
&lt;BR /&gt;
-------------------------------------------------------------------&lt;BR /&gt;
&lt;BR /&gt;
Then, when the above value &amp;amp;filenm is used in the proc export, the following error is issued:&lt;BR /&gt;
&lt;BR /&gt;
230  %macro exportxl (setnm = );&lt;BR /&gt;
231  PROC EXPORT DATA= &amp;amp;setnm&lt;BR /&gt;
232              OUTFILE= &amp;amp;filenm&lt;BR /&gt;
233              DBMS=EXCEL REPLACE;&lt;BR /&gt;
234       SHEET=&amp;amp;setnm;&lt;BR /&gt;
235  RUN;&lt;BR /&gt;
236  %mend exportxl;&lt;BR /&gt;
237&lt;BR /&gt;
238  %exportxl (setnm = p2);&lt;BR /&gt;
&lt;BR /&gt;
1     'I:\1 Commissions\PPA\Audit\' || '2009_09' || '\insues_091409.xls'&lt;BR /&gt;
ERROR 22-322: Syntax error, expecting one of the following: ;, DATA, DBMS, FILE, OUTFILE,&lt;BR /&gt;
              OUTTABLE, REPLACE, TABLE.</description>
      <pubDate>Mon, 14 Sep 2009 16:37:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-dataset-to-Excel-with-filename-var/m-p/71240#M15408</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-09-14T16:37:49Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to export dataset to Excel with filename var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-dataset-to-Excel-with-filename-var/m-p/71241#M15409</link>
      <description>For my visual-programming interests/needs, I tend to lean on the TRANWRD function using a macro variable to substitute of a pattern-string with a template variable being referenced - as shown below:&lt;BR /&gt;
&lt;BR /&gt;
%LET XOUTFILE = BIG.WOOLY.MONTHLY.DATA.Myyyymm.CSV;&lt;BR /&gt;
* PROC SQL or DATA STEP (SYMPUT) code to generate &amp;amp;PERIOD. ;&lt;BR /&gt;
* ...the outcome is demonstrated below. ;&lt;BR /&gt;
%let period = 200909;&lt;BR /&gt;
%LET OUTFILE = %SYSFUNC(TRANWRD(&amp;amp;XOUTFILE,yyyymm,&amp;amp;PERIOD));&lt;BR /&gt;
%put _user_;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Mon, 14 Sep 2009 16:53:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-dataset-to-Excel-with-filename-var/m-p/71241#M15409</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-09-14T16:53:57Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to export dataset to Excel with filename var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-dataset-to-Excel-with-filename-var/m-p/71242#M15410</link>
      <description>I think I got it -- I didn't know about using period as concatenator.&lt;BR /&gt;
&lt;BR /&gt;
%macro exportxl (librf, setnm);&lt;BR /&gt;
PROC EXPORT DATA= &amp;amp;librf..&amp;amp;setnm&lt;BR /&gt;
            OUTFILE= "&amp;amp;prefixnm.&amp;amp;filenm..xls"&lt;BR /&gt;
            DBMS=EXCEL REPLACE;&lt;BR /&gt;
     SHEET=setnm; &lt;BR /&gt;
RUN;&lt;BR /&gt;
%mend exportxl;&lt;BR /&gt;
&lt;BR /&gt;
%let prefixnm = I:\1 Commissions\PPA\Audit\2009_09\;&lt;BR /&gt;
%let filenm = \insues_091409;&lt;BR /&gt;
%exportxl(ppabon08,p2);</description>
      <pubDate>Mon, 14 Sep 2009 19:52:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-dataset-to-Excel-with-filename-var/m-p/71242#M15410</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-09-14T19:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to export dataset to Excel with filename var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-dataset-to-Excel-with-filename-var/m-p/71243#M15411</link>
      <description>I believe that if you call Tech Support and explain what you need, they can submit an enhancement request for you and route it to the proper group(s) for consideration.</description>
      <pubDate>Thu, 17 Sep 2009 12:03:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-dataset-to-Excel-with-filename-var/m-p/71243#M15411</guid>
      <dc:creator>PatrickG</dc:creator>
      <dc:date>2009-09-17T12:03:24Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to export dataset to Excel with filename var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-dataset-to-Excel-with-filename-var/m-p/71244#M15412</link>
      <description>Enhancement?  The use of %SYSFUNC opens up the use of DATA STEP functions within the macro language.  From the original OP, the function used CONCAT was invalid and unnecessary within the macro language.  The CAT function coded within a %SYSFUNC( ) would have worked fine or the use of macro variables as was demonstrated.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 17 Sep 2009 12:24:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-export-dataset-to-Excel-with-filename-var/m-p/71244#M15412</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-09-17T12:24:51Z</dc:date>
    </item>
  </channel>
</rss>

