<?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 variable in macro name in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-in-macro-name/m-p/642511#M21871</link>
    <description>My solution (which I've finalised since my last response is to hardcode the macro name as:&lt;BR /&gt;%macro temp;&lt;BR /&gt;conclude it with:&lt;BR /&gt;%mend temp;&lt;BR /&gt;then check temp is created:&lt;BR /&gt;data _null_;&lt;BR /&gt;attrib a format=1.;&lt;BR /&gt;/* check log for the following message from the put statement */&lt;BR /&gt;put "Macro ran successfully - delimiters (e.g. single/double quotes ok";&lt;BR /&gt;a=%sysmacexist(temp);&lt;BR /&gt;put a=;&lt;BR /&gt;if a=1 then&lt;BR /&gt;put "Macro temp created successfully";&lt;BR /&gt;else&lt;BR /&gt;put "Macro temp not created - check for errors";&lt;BR /&gt;run;&lt;BR /&gt;and then rename the macro:&lt;BR /&gt;proc catalog cat=work.sasmacr;&lt;BR /&gt;change temp=&amp;amp;macroname. /et=macro;&lt;BR /&gt;run;&lt;BR /&gt;Then use the original final step to check the rename has worked:&lt;BR /&gt;data _null_;&lt;BR /&gt;attrib a format=1.;&lt;BR /&gt;/* check log for the following message from the put statement */&lt;BR /&gt;put "Macro ran successfully - delimiters (e.g. single/double quotes ok";&lt;BR /&gt;a=%sysmacexist(&amp;amp;macroname.);&lt;BR /&gt;put a=;&lt;BR /&gt;if a=1 then&lt;BR /&gt;put "Macro &amp;amp;macroname. created successfully";&lt;BR /&gt;else&lt;BR /&gt;put "Macro &amp;amp;macroname. not created - check for errors";&lt;BR /&gt;run;</description>
    <pubDate>Fri, 24 Apr 2020 10:50:58 GMT</pubDate>
    <dc:creator>ishmo65</dc:creator>
    <dc:date>2020-04-24T10:50:58Z</dc:date>
    <item>
      <title>macro variable in macro name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-in-macro-name/m-p/604402#M17058</link>
      <description>&lt;P&gt;running&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let var = 1;

%macro mac_&amp;amp;var.;
  %put emmanuel macro;
%mend;

%mac_1;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;gives&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1      %let var = 1;
2
3      %macro mac_&amp;amp;var.;
ERROR: Expected semicolon not found.  The macro will not be compiled.
ERROR: A dummy macro will be compiled.
4        %put emmanuel macro;
5      %mend;
6
7      %mac_1;
       -
       180
WARNING: Apparent invocation of macro MAC_1 not resolved.

ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;what's wrong with it? can't i use macro variables in the definition of macros?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2019 07:54:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-variable-in-macro-name/m-p/604402#M17058</guid>
      <dc:creator>Quodly</dc:creator>
      <dc:date>2019-11-15T07:54:00Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable in macro name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-in-macro-name/m-p/604404#M17059</link>
      <description>&lt;P&gt;As the&amp;nbsp;&lt;A href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p1nypovnwon4uyn159rst8pgzqrl.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;%MACRO Statement Documentation&lt;/A&gt; says:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;"you cannot use a&amp;nbsp;&lt;SPAN class="ng-scope" data-gloss-modified="" data-gloss-item="1"&gt;&lt;SPAN class="xis-glossTerm ng-scope" data-gloss-term="1"&gt;text expression&lt;/SPAN&gt;&lt;/SPAN&gt;&amp;nbsp;to generate a macro name in a %MACRO statement."&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2019 08:02:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-variable-in-macro-name/m-p/604404#M17059</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-11-15T08:02:57Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable in macro name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-in-macro-name/m-p/604545#M17096</link>
      <description>&lt;P&gt;If you can describe why you thought you needed this sort of naming we may be able to provide alternate approaches to accomplish something similar.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2019 17:02:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-variable-in-macro-name/m-p/604545#M17096</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-11-15T17:02:27Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable in macro name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-in-macro-name/m-p/604601#M17119</link>
      <description>&lt;P&gt;You seem to confused.&lt;/P&gt;
&lt;P&gt;Did you mean to do something like this instead?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro mac_1;
  %put First Macro ;
%mend;
%macro mac_2;
  %put Second Macro ;
%mend;
....
%let var = 1;
%mac_&amp;amp;var. ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Nov 2019 19:38:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-variable-in-macro-name/m-p/604601#M17119</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-15T19:38:08Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable in macro name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-in-macro-name/m-p/609331#M17870</link>
      <description>sorry for my late reply. i wanted to define macros inside a macro loop, each macro named differently. i did it another way now. thanks anyway!</description>
      <pubDate>Wed, 04 Dec 2019 11:06:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-variable-in-macro-name/m-p/609331#M17870</guid>
      <dc:creator>Quodly</dc:creator>
      <dc:date>2019-12-04T11:06:24Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable in macro name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-in-macro-name/m-p/609365#M17881</link>
      <description>You do not ever need (or want) to redefine a MACRO inside of a loop.  Perhaps instead you meant that you want to define a new macro VARIABLE in a loop?&lt;BR /&gt;%do i=1 %to %sysfunc(countw(&amp;amp;list,%str( ))); %let element=%scan(&amp;amp;list,&amp;amp;I,%str( )); .... %end;&lt;BR /&gt;Or you meant to CALL a macro inside the loop?&lt;BR /&gt;%do i=1 %to %sysfunc(countw(&amp;amp;list,%str( ))); %sub_macro(%scan(&amp;amp;list,&amp;amp;I,%str( ))); %end;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 04 Dec 2019 13:06:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-variable-in-macro-name/m-p/609365#M17881</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-04T13:06:55Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable in macro name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-in-macro-name/m-p/642508#M21870</link>
      <description>&lt;P&gt;Is there any way I can do this ?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;;;;;;
options mprint mlogic symbolgen;
options mautocomploc;
%let macroname=temp;

%sysmacdelete &amp;amp;macroname.;

%macro &amp;amp;macroname.(var1,var2);
	%put Macro started: &amp;amp;macroname.;
	%put ===============================;

/* macro code here */

	%put Macro ended: &amp;amp;macroname.;
	%put =============================;

%mend &amp;amp;macroname.;

data _null_;
	attrib a format=1.;
	/* check log for the following message from the put statement */
	put "Macro ran successfully - delimiters (e.g. single/double quotes ok";
	a=%sysmacexist(&amp;amp;macroname.);
	put a=;
	if a=1 then
		put "&amp;amp;macroname. created successfully";
	else
		put "&amp;amp;macroname. not created - check for errors";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The code outside of the macro works but the macro create fails with:&lt;/P&gt;&lt;PRE&gt;11049  %macro &amp;amp;macroname.(var1,var2);
ERROR: Invalid macro name &amp;amp;.  It should be a valid SAS identifier no longer than 32 characters.
...
11281  %mend &amp;amp;macroname.;
WARNING: Extraneous text on %MEND statement ignored for macro definition .&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Apr 2020 10:35:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-variable-in-macro-name/m-p/642508#M21870</guid>
      <dc:creator>ishmo65</dc:creator>
      <dc:date>2020-04-24T10:35:10Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable in macro name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-in-macro-name/m-p/642511#M21871</link>
      <description>My solution (which I've finalised since my last response is to hardcode the macro name as:&lt;BR /&gt;%macro temp;&lt;BR /&gt;conclude it with:&lt;BR /&gt;%mend temp;&lt;BR /&gt;then check temp is created:&lt;BR /&gt;data _null_;&lt;BR /&gt;attrib a format=1.;&lt;BR /&gt;/* check log for the following message from the put statement */&lt;BR /&gt;put "Macro ran successfully - delimiters (e.g. single/double quotes ok";&lt;BR /&gt;a=%sysmacexist(temp);&lt;BR /&gt;put a=;&lt;BR /&gt;if a=1 then&lt;BR /&gt;put "Macro temp created successfully";&lt;BR /&gt;else&lt;BR /&gt;put "Macro temp not created - check for errors";&lt;BR /&gt;run;&lt;BR /&gt;and then rename the macro:&lt;BR /&gt;proc catalog cat=work.sasmacr;&lt;BR /&gt;change temp=&amp;amp;macroname. /et=macro;&lt;BR /&gt;run;&lt;BR /&gt;Then use the original final step to check the rename has worked:&lt;BR /&gt;data _null_;&lt;BR /&gt;attrib a format=1.;&lt;BR /&gt;/* check log for the following message from the put statement */&lt;BR /&gt;put "Macro ran successfully - delimiters (e.g. single/double quotes ok";&lt;BR /&gt;a=%sysmacexist(&amp;amp;macroname.);&lt;BR /&gt;put a=;&lt;BR /&gt;if a=1 then&lt;BR /&gt;put "Macro &amp;amp;macroname. created successfully";&lt;BR /&gt;else&lt;BR /&gt;put "Macro &amp;amp;macroname. not created - check for errors";&lt;BR /&gt;run;</description>
      <pubDate>Fri, 24 Apr 2020 10:50:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-variable-in-macro-name/m-p/642511#M21871</guid>
      <dc:creator>ishmo65</dc:creator>
      <dc:date>2020-04-24T10:50:58Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable in macro name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-in-macro-name/m-p/642519#M21872</link>
      <description>That didn't wok - running the macro resulted in the following errors:&lt;BR /&gt;ERROR: The macro name XYZ and the internal macro header name TEMP in the SASMACR macro catalog differ. Recompile this macro and try again.&lt;BR /&gt;ERROR: Macro library damaged. Cannot execute macro XYZ on V9.x compiled using V9.3x on DDMMYY.&lt;BR /&gt;</description>
      <pubDate>Fri, 24 Apr 2020 11:19:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-variable-in-macro-name/m-p/642519#M21872</guid>
      <dc:creator>ishmo65</dc:creator>
      <dc:date>2020-04-24T11:19:16Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable in macro name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-in-macro-name/m-p/642548#M21873</link>
      <description>&lt;P&gt;Not sure why you posted a new question into an old thread.&amp;nbsp; But the answer is still the same. You cannot use macro variables to generate the %MACRO statement.&amp;nbsp; I doubt there is any real problem that requites that you do that, but if insist on dynamically generating code to create a %MACRO statement then use some other method of code generation. Such as writing the code to a file and %INCLUDING the file.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 12:20:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-variable-in-macro-name/m-p/642548#M21873</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-24T12:20:16Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable in macro name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-in-macro-name/m-p/742472#M29195</link>
      <description>&lt;P&gt;One approach could be as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

%let macroname=temp;

%sysmacdelete &amp;amp;macroname. / nowarn;

data _null_;
length code $ 32767; 
retain code " ";

input;
 code = catx(" ",code,_infile_);

 if _N_ = 2 then code = catx(" ", code, symget("macroname"));

 if strip(_infile_) =: '%mend' then 
  do;
    put code;
    rc = resolve(code);
  end;
cards4;
%macro 
/*&amp;amp;macroname.*/
(var1,var2);
%put Macro started: &amp;amp;SYSMACRONAME.;
%put ===============================;

/* macro code here */

%put Macro ended: &amp;amp;SYSMACRONAME.;
%put =============================;

%mend;
;;;;
run;

data _null_;
	attrib a format=1.;
	/* check log for the following message from the put statement */
	put "Macro ran successfully - delimiters (e.g. single/double quotes ok";
	a=%sysmacexist(&amp;amp;macroname.);
	put a=;
	if a=1 then
		put "&amp;amp;macroname. created successfully";
	else
		put "&amp;amp;macroname. not created - check for errors";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 17:14:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-variable-in-macro-name/m-p/742472#M29195</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-05-19T17:14:30Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable in macro name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/macro-variable-in-macro-name/m-p/742478#M29196</link>
      <description>&lt;P&gt;or even simpler:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
length code $ 32767; 
code = '
(var1,var2);
%put Macro started: &amp;amp;SYSMACRONAME.;
%put ===============================;

/* macro code here */

%put Macro ended: &amp;amp;SYSMACRONAME.;
%put =============================;

%mend;
';
rc = resolve('%macro ' !! " &amp;amp;macroname." !! code);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;B.&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 17:46:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/macro-variable-in-macro-name/m-p/742478#M29196</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-05-19T17:46:04Z</dc:date>
    </item>
  </channel>
</rss>

