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

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1378 views
  • 1 like
  • 4 in conversation