<?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: Trouble with folder macro in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Trouble-with-folder-macro/m-p/960120#M43136</link>
    <description>&lt;P&gt;Your posted code for defining the macro is not correct as the %MACRO statement is wrong.&amp;nbsp; But perhaps that is just a typo since you also say it works.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro make_excel(dataset= , output_path = , filname = );
ods excel file = "&amp;amp;output_path.\&amp;amp;filename..xlsx";
proc report data= &amp;amp;dataset.;
run;
ods excel close; 
%mend make_excel;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You are not referencing the macro variable OUT_TMP properly in your macro call.&amp;nbsp; You used % instead of &amp;amp;.&amp;nbsp; The % character is used to reference macros statements (like the %MACRO and %MEND in your code) and actual macro functions (like %SUBSTR() and %SCAN()) in addition to being used to reference macros (like %MAKE_EXCEL in your program). The&amp;nbsp; &amp;amp; character is used when you need to reference a macro variable (also known as a symbol).&amp;nbsp;&amp;nbsp;You are using the &amp;amp; properly to reference the macro variables correctly in the body of your macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the fixed macro call:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%make_excel(dataset=ds, output_path = &amp;amp;out_tmp, filename = YYYYYYY)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 24 Feb 2025 21:50:13 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-02-24T21:50:13Z</dc:date>
    <item>
      <title>Trouble with folder macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trouble-with-folder-macro/m-p/960106#M43133</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm a novice at SAS macro and am having some issues writing a function which does the following:&lt;/P&gt;&lt;P&gt;takes 3 inputs&lt;/P&gt;&lt;P&gt;1. dataset name (e.g. from a data step)&lt;/P&gt;&lt;P&gt;2. a folder directory where all of various excel outputs will be stored&lt;/P&gt;&lt;P&gt;3. the desired excel file name for the dataset&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have currently written my function as follows:&lt;/P&gt;&lt;P&gt;%make_excel(dataset= , output_path = , filname = );&lt;/P&gt;&lt;P&gt;ods excel file = "&amp;amp;output_path.\&amp;amp;filename..xlsx";&lt;/P&gt;&lt;P&gt;proc report data= &amp;amp;dataset.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;ods excel close;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%mend make_Excel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Presently if I call the function with something like:&lt;/P&gt;&lt;P&gt;%make_excel(dataset= ds, output_path = C:\Users\XXXXX, filename = YYYYY)&amp;nbsp;&lt;/P&gt;&lt;P&gt;everything works fine, which is great. But I need to call the function a bunch of times and I don't want to constantly copy/paste the output path. So I'm trying to set a macro variable such as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let out_tmp =&amp;nbsp;C:\Users\XXXXX;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And then call the function by&lt;/P&gt;&lt;P&gt;%make_excel(dataset=ds, output_path = %out_tmp, filename = YYYYYYY)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when I am trying this I keep getting an error in the long:&lt;/P&gt;&lt;P&gt;"Error: physical file does not exist, C:\Windows\systsem32\%out_tmp\YYYYY.xlsx"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ChatGPT and google have unfortunately been no help so far. Any idea why this might be occurring?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 20:18:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trouble-with-folder-macro/m-p/960106#M43133</guid>
      <dc:creator>bm343</dc:creator>
      <dc:date>2025-02-24T20:18:26Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with folder macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trouble-with-folder-macro/m-p/960109#M43134</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/473844"&gt;@bm343&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And then call the function by&lt;/P&gt;
&lt;P&gt;make_excel(dataset=ds, output_path = out_tmp, filename = YYYYYYY)&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;There are two errors here, it should be&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;%&lt;/STRONG&gt;&lt;/FONT&gt;make_excel(dataset=ds, output_path = &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;&amp;amp;&lt;/FONT&gt;&lt;/STRONG&gt;out_tmp, filename = YYYYYYY)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To call any macro, you must use a % before the macro name, so here it must be %make_excel&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To use any macro variable, you have to use an &amp;amp; before the macro variable name, so here it must be &amp;amp;out_tmp&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 20:17:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trouble-with-folder-macro/m-p/960109#M43134</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-02-24T20:17:51Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with folder macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trouble-with-folder-macro/m-p/960112#M43135</link>
      <description>&lt;P&gt;that seems to have resolved it, thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 20:20:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trouble-with-folder-macro/m-p/960112#M43135</guid>
      <dc:creator>bm343</dc:creator>
      <dc:date>2025-02-24T20:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with folder macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trouble-with-folder-macro/m-p/960120#M43136</link>
      <description>&lt;P&gt;Your posted code for defining the macro is not correct as the %MACRO statement is wrong.&amp;nbsp; But perhaps that is just a typo since you also say it works.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro make_excel(dataset= , output_path = , filname = );
ods excel file = "&amp;amp;output_path.\&amp;amp;filename..xlsx";
proc report data= &amp;amp;dataset.;
run;
ods excel close; 
%mend make_excel;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You are not referencing the macro variable OUT_TMP properly in your macro call.&amp;nbsp; You used % instead of &amp;amp;.&amp;nbsp; The % character is used to reference macros statements (like the %MACRO and %MEND in your code) and actual macro functions (like %SUBSTR() and %SCAN()) in addition to being used to reference macros (like %MAKE_EXCEL in your program). The&amp;nbsp; &amp;amp; character is used when you need to reference a macro variable (also known as a symbol).&amp;nbsp;&amp;nbsp;You are using the &amp;amp; properly to reference the macro variables correctly in the body of your macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the fixed macro call:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%make_excel(dataset=ds, output_path = &amp;amp;out_tmp, filename = YYYYYYY)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 21:50:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trouble-with-folder-macro/m-p/960120#M43136</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-02-24T21:50:13Z</dc:date>
    </item>
  </channel>
</rss>

