<?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: define macro name using macro variable in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/define-macro-name-using-macro-variable/m-p/802294#M40407</link>
    <description>No idea of how, but out of curiousity what's the use case for such macro development? &lt;BR /&gt;&lt;BR /&gt;Dynamically writing macro's isn't a use case I've seen in 20 years of programming.</description>
    <pubDate>Tue, 15 Mar 2022 17:45:29 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-03-15T17:45:29Z</dc:date>
    <item>
      <title>define macro name using macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/define-macro-name-using-macro-variable/m-p/802289#M40406</link>
      <description>&lt;P&gt;I want to create several macros with similar names, for example, m1, m2, m3, m4, m5. Since their name might change, I would prefer to name them using a macro variable so that the only thing I have to change in case the name changes is the macro variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, instead of having&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro m1;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;%macro m5;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to have&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let c=1;&lt;/P&gt;&lt;P&gt;%macro m&amp;amp;c.;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;%let c=5;&lt;/P&gt;&lt;P&gt;%macro m&amp;amp;c.;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I believe you cannot use the '&amp;amp;' symbol in macro's names. Is there any other way to do this?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 17:28:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/define-macro-name-using-macro-variable/m-p/802289#M40406</guid>
      <dc:creator>Babado</dc:creator>
      <dc:date>2022-03-15T17:28:37Z</dc:date>
    </item>
    <item>
      <title>Re: define macro name using macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/define-macro-name-using-macro-variable/m-p/802294#M40407</link>
      <description>No idea of how, but out of curiousity what's the use case for such macro development? &lt;BR /&gt;&lt;BR /&gt;Dynamically writing macro's isn't a use case I've seen in 20 years of programming.</description>
      <pubDate>Tue, 15 Mar 2022 17:45:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/define-macro-name-using-macro-variable/m-p/802294#M40407</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-03-15T17:45:29Z</dc:date>
    </item>
    <item>
      <title>Re: define macro name using macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/define-macro-name-using-macro-variable/m-p/802308#M40409</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;However, I believe you cannot use the '&amp;amp;' symbol in macro's names. Is there any other way to do this?&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;If you are getting errors, turn on the macro debugging options, run your code again, and show us the log. Don't make us guess what is wrong.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options symbolgen mlogic mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Also, agreeing with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;whatever you are doing, there are probably easier methods. And so this is critically important: explain what you are trying to do.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 18:17:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/define-macro-name-using-macro-variable/m-p/802308#M40409</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-15T18:17:07Z</dc:date>
    </item>
    <item>
      <title>Re: define macro name using macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/define-macro-name-using-macro-variable/m-p/802313#M40410</link>
      <description>&lt;P&gt;Sounds like a recipe for confusion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the information to write a text file with the desired code and %include the file for the macro definition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can call macro with the macro variable in the name after it is defined.&lt;/P&gt;
&lt;P&gt;Something like this:&lt;/P&gt;
&lt;PRE&gt;%let c=p;

data _null_;
file "&amp;lt;path&amp;gt;\dummy&amp;amp;c.sas";
put "%macro dummy&amp;amp;c ();";
put "  proc print data=sashelp.class;";
put "  run;";
put "%mend;";
run;

%include  "&amp;lt;path&amp;gt;\dummy&amp;amp;c.sas";

%dummy&amp;amp;c.;&lt;/PRE&gt;
&lt;P&gt;If you place the file in an AUTOCALL library location and are careful with the file names you wouldn't need the %include step to compile the macro. This works because the macro variable in the %macro statement gets resolved in the data step and written as text and not seen by the macro compiler until the %include attempts to compile it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 18:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/define-macro-name-using-macro-variable/m-p/802313#M40410</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-15T18:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: define macro name using macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/define-macro-name-using-macro-variable/m-p/802396#M40411</link>
      <description>&lt;P&gt;You cannot use macro expressions in the NAME of a macro.&lt;/P&gt;
&lt;P&gt;Use some other code generator to generate the source code for your macros.&amp;nbsp; Like CALL EXECUTE() or writing text to a file and using %INCLUDE to run it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you would explain why you thought that might be useful perhaps someone can show you another way that will work.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 00:46:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/define-macro-name-using-macro-variable/m-p/802396#M40411</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-16T00:46:56Z</dc:date>
    </item>
  </channel>
</rss>

