As the %Macro Statement Documentation says: "A macro name must be a SAS name, which you supply; you cannot use a text expression to generate a macro name in a %MACRO statement".
Which means that you can not use a macro variable in a %Macro Statement.
Why do you want to create macros with dynamic names? It makes your code hard. Here is one way:
%let sex=F;
options mprint;
data _null_;
macro_name = "&sex";
call execute('%nrstr(%macro '!!macro_name!!';)');
call execute('%nrstr(proc print data = sashelp.class;run;)');
call execute('%nrstr(%mend '!!macro_name!!';)');
call execute('%nrstr(%'!!macro_name!!';)');
run;
You could also write the same statements to an external text file then %INCLUDE them.
First of all, why do you want to create a macro with a dynamic name? The dynamic part of a macro should be its arguments.
Even if you could, you don't. It creates unmaintainable code.
DO NOT DO IT. DO NOT EVEN THINK ABOUT IT.
What for do you even think this is needed?
And what is the difference between those macros? You're much better off creating one macro that expects one of F,M,O as a parameter and acts accordingly.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.