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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.