BookmarkSubscribeRSS Feed
thanikondharish
Fluorite | Level 6
%let sex=F;
%macro &sex;
Proc print data=sashelp.class;
Run;
%mend;

%&sex;

I wrote one application but i am getting error .
Please help to fix this
7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20

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.

thanikondharish
Fluorite | Level 6
Thaks,
Is there any other option?
SASKiwi
PROC Star

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.

PeterClemmensen
Tourmaline | Level 20

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.

thanikondharish
Fluorite | Level 6
I want to create 3 macro applici at a time
1-F
2-M
3-O

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1306 views
  • 1 like
  • 4 in conversation