<?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: Calling macro twice wont work, while calling it once works fine in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Calling-macro-twice-wont-work-while-calling-it-once-works-fine/m-p/611404#M23608</link>
    <description>&lt;P&gt;I think&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;is right about not having and &lt;FONT face="courier new,courier"&gt;ODS EXCEL CLOSE;&lt;/FONT&gt; statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But this particular error is not a macro issue&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I run this code twice (note: I deliberately did not include &lt;FONT face="courier new,courier"&gt;ODS EXCEL CLOSE;&lt;/FONT&gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods excel file="test.xlsx";
proc print data=sashelp.class;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I get this error on the second run of the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ERROR: No body file. EXCEL output will not be created.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 12 Dec 2019 17:34:15 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-12-12T17:34:15Z</dc:date>
    <item>
      <title>Calling macro twice wont work, while calling it once works fine</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Calling-macro-twice-wont-work-while-calling-it-once-works-fine/m-p/611392#M23605</link>
      <description>&lt;P&gt;INFO:&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS EG 7.15&lt;/P&gt;&lt;P&gt;Server-setup from a workplace&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi Guys! Quite new to sas here.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've managed to write a macro that exports already produced datasets, which works perfectly when I call the macro the first time. Second time I call the macro, it seems to ignore the first call, write out an excel-file with the correct name (the name for the second call) but the sheets and data are from the first call.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm doing this for six datasets in this case. So when I call the macro 6 times, very oddly, the macro again skips first call, writes out second call with first call data, writes out third call correctly with third call data, fourth call with third call data, fifth call with fourth call data and sixth with fifth. So NOT in a specific pattern as I see it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to add, that the macro works perfectly when it is called ONCE no matter which call I make.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ultimate(file, sheet1, sheet2, sheet3, data1, data2, data3);
ods excel file="&amp;lt;*FILEPATH*&amp;gt;/&amp;amp;file..xlsx"  style=meadow
        options(
				sheet_interval='bygroup'
				frozen_headers='1'
				);
ods excel options(sheet_name=&amp;amp;sheet1);
PROC print
data=&amp;amp;data1 noobs;
id Kontonr Type Tjenestenr Navn;
sum '01'n '02'n '03'n '04'n '05'n '06'n '07'n '08'n '09'n '10'n '11'n '12'n 'Forventet_Lønudgift'n;
run;
ods excel options(sheet_name=&amp;amp;sheet2);
PROC print
data=&amp;amp;data2 noobs;
id Kontonr Type Tjenestenr Navn lonart_tekst;
sum '01'n '02'n '03'n '04'n '05'n '06'n '07'n '08'n '09'n '10'n '11'n '12'n 'Forventet_udgift'n;
run;
ods excel options(sheet_name=&amp;amp;sheet3);
PROC print
data=&amp;amp;data3 noobs;
id aar Tjenestenr Navn fravaersaarsag dato_fravaer_start dato_fravaer_slut;
run;
%mend ultimate;

%ultimate(JU1, 'JU1', 'JU1 Lønart', 'JU1 Fravær', work.ju1, work.ju1_loenart, work.'fravær_ju1'n);

%ultimate(JU2, 'JU2', 'JU2 Lønart', 'JU2 Fravær', work.ju2, work.ju2_loenart, work.'fravær_ju2'n);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error im getting is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Physical file does not exist&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: No body file. EXCEL output will not be created&lt;/P&gt;&lt;P&gt;(Which is btw a LIE because it does create excel outputs, just in a weird and wrong way!)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Insufficient authorization to access&amp;nbsp;/sas/prod/config_18W04/Lev1/EGApp/sasexcl.xlsx.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Disclaimer, I'm sure you guys will have a thousand ways to optimize the above, those are welcome if you really can't help it &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much in advance!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Eager new sas-user&lt;/P&gt;&lt;P&gt;Hussam&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS. Hope I managed to bring in all the relevant info on my first post on here&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2019 17:13:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Calling-macro-twice-wont-work-while-calling-it-once-works-fine/m-p/611392#M23605</guid>
      <dc:creator>HussamAlSaffar</dc:creator>
      <dc:date>2019-12-12T17:13:43Z</dc:date>
    </item>
    <item>
      <title>Re: Calling macro twice wont work, while calling it once works fine</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Calling-macro-twice-wont-work-while-calling-it-once-works-fine/m-p/611400#M23606</link>
      <description>&lt;P&gt;You don't have an ODS EXCEL CLOSE that I can see, which you need to close the file and finish the processing of the Excel file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm guessing your file path is incorrect as well.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general, when writing macro code you should have working code that first works and then you convert it to a macro. Do you have base working code first?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's some macro references that may help you out.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UCLA introductory tutorial on macro variables and macros&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Tutorial on converting a working program to a macro&lt;BR /&gt;&lt;BR /&gt;This method is pretty robust and helps prevent errors and makes it much easier to debug your code. Obviously biased, because I wrote it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Examples of common macro usage&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716&amp;nbsp;" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716&amp;nbsp;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292982"&gt;@HussamAlSaffar&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;INFO:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS EG 7.15&lt;/P&gt;
&lt;P&gt;Server-setup from a workplace&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi Guys! Quite new to sas here.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've managed to write a macro that exports already produced datasets, which works perfectly when I call the macro the first time. Second time I call the macro, it seems to ignore the first call, write out an excel-file with the correct name (the name for the second call) but the sheets and data are from the first call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm doing this for six datasets in this case. So when I call the macro 6 times, very oddly, the macro again skips first call, writes out second call with first call data, writes out third call correctly with third call data, fourth call with third call data, fifth call with fourth call data and sixth with fifth. So NOT in a specific pattern as I see it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to add, that the macro works perfectly when it is called ONCE no matter which call I make.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any ideas?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ultimate(file, sheet1, sheet2, sheet3, data1, data2, data3);
ods excel file="&amp;lt;*FILEPATH*&amp;gt;/&amp;amp;file..xlsx"  style=meadow
        options(
				sheet_interval='bygroup'
				frozen_headers='1'
				);
ods excel options(sheet_name=&amp;amp;sheet1);
PROC print
data=&amp;amp;data1 noobs;
id Kontonr Type Tjenestenr Navn;
sum '01'n '02'n '03'n '04'n '05'n '06'n '07'n '08'n '09'n '10'n '11'n '12'n 'Forventet_Lønudgift'n;
run;
ods excel options(sheet_name=&amp;amp;sheet2);
PROC print
data=&amp;amp;data2 noobs;
id Kontonr Type Tjenestenr Navn lonart_tekst;
sum '01'n '02'n '03'n '04'n '05'n '06'n '07'n '08'n '09'n '10'n '11'n '12'n 'Forventet_udgift'n;
run;
ods excel options(sheet_name=&amp;amp;sheet3);
PROC print
data=&amp;amp;data3 noobs;
id aar Tjenestenr Navn fravaersaarsag dato_fravaer_start dato_fravaer_slut;
run;
%mend ultimate;

%ultimate(JU1, 'JU1', 'JU1 Lønart', 'JU1 Fravær', work.ju1, work.ju1_loenart, work.'fravær_ju1'n);

%ultimate(JU2, 'JU2', 'JU2 Lønart', 'JU2 Fravær', work.ju2, work.ju2_loenart, work.'fravær_ju2'n);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The error im getting is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: Physical file does not exist&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: No body file. EXCEL output will not be created&lt;/P&gt;
&lt;P&gt;(Which is btw a LIE because it does create excel outputs, just in a weird and wrong way!)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: Insufficient authorization to access&amp;nbsp;/sas/prod/config_18W04/Lev1/EGApp/sasexcl.xlsx.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Disclaimer, I'm sure you guys will have a thousand ways to optimize the above, those are welcome if you really can't help it &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much in advance!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best&lt;/P&gt;
&lt;P&gt;Eager new sas-user&lt;/P&gt;
&lt;P&gt;Hussam&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS. Hope I managed to bring in all the relevant info on my first post on here&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2019 17:21:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Calling-macro-twice-wont-work-while-calling-it-once-works-fine/m-p/611400#M23606</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-12-12T17:21:23Z</dc:date>
    </item>
    <item>
      <title>Re: Calling macro twice wont work, while calling it once works fine</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Calling-macro-twice-wont-work-while-calling-it-once-works-fine/m-p/611403#M23607</link>
      <description>Awh man it was the ODS EXCEL CLOSE All along! So silly. Thanks a lot!&lt;BR /&gt;&lt;BR /&gt;Btw. I did create a working program before trying to expand it, so I completely agree that that is the way to go about creating any program.&lt;BR /&gt;&lt;BR /&gt;Thanks again!!</description>
      <pubDate>Thu, 12 Dec 2019 17:33:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Calling-macro-twice-wont-work-while-calling-it-once-works-fine/m-p/611403#M23607</guid>
      <dc:creator>HussamAlSaffar</dc:creator>
      <dc:date>2019-12-12T17:33:41Z</dc:date>
    </item>
    <item>
      <title>Re: Calling macro twice wont work, while calling it once works fine</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Calling-macro-twice-wont-work-while-calling-it-once-works-fine/m-p/611404#M23608</link>
      <description>&lt;P&gt;I think&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;is right about not having and &lt;FONT face="courier new,courier"&gt;ODS EXCEL CLOSE;&lt;/FONT&gt; statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But this particular error is not a macro issue&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I run this code twice (note: I deliberately did not include &lt;FONT face="courier new,courier"&gt;ODS EXCEL CLOSE;&lt;/FONT&gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods excel file="test.xlsx";
proc print data=sashelp.class;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I get this error on the second run of the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ERROR: No body file. EXCEL output will not be created.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2019 17:34:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Calling-macro-twice-wont-work-while-calling-it-once-works-fine/m-p/611404#M23608</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-12T17:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: Calling macro twice wont work, while calling it once works fine</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Calling-macro-twice-wont-work-while-calling-it-once-works-fine/m-p/611407#M23609</link>
      <description>I think ODS has change the defaults, it should be BODY= not FILE= in the newest versions of SAS in the ODS statement.</description>
      <pubDate>Thu, 12 Dec 2019 17:36:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Calling-macro-twice-wont-work-while-calling-it-once-works-fine/m-p/611407#M23609</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-12-12T17:36:18Z</dc:date>
    </item>
  </channel>
</rss>

