BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
CurtisSmithDCAA
Obsidian | Level 7

Hi. I'm trying to use a macro variable in the name of a %macro statement. For example:

 

%let app=hello;

%macro analyze_byvar_&&app.;

.

.

.

%mend analyze_byvar_&&app.;

 

However, when I invoke the macro the name does not resolve.

 

Any suggestions?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

names the macro. 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. In addition, do not use macro reserved words as a macro name.

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

names the macro. 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. In addition, do not use macro reserved words as a macro name.

Astounding
PROC Star

The reference to a macro variable works when invoking a macro.  This should be fine:

 

%analyze_byvar_&app.

 

However, it doesn't work when naming a macro.

ballardw
Super User

In almost any approach that I can imagine whatever you may be attempting it would likely be much better to have a single macro and have the value you are calling APP as a parameter to the macro. Since you do not show any parameters I suspect you need to delve a little further into macro language documentation.

 

If you had shown what that macro is supposed to actually do we might make more constructive comments.

 

Show us log where you compiled the macro. I suspect that it did not compile.

art297
Opal | Level 21

@CurtisSmithDCAA: I disagree! If you need to create a macro whose name includes a macro variable you could always simply create it as an include file. e.g.:

 

%let app=hello;
filename testit '/folders/myfolders/testit.sas';
data _null_;
  length forinc $80;
  file testit;
  forinc=catt('%macro analyze_byvar_',"&app",';');
  put forinc;
  put 'x=1;';
  forinc=catt('%mend analyze_byvar_',"&app",';');
  put forinc;
run;

%include testit;
data test;
  input y;
  %analyze_byvar_hello;
  cards;
1
2
3
;

Art, CEO, AnalystFinder.com

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1065 views
  • 5 likes
  • 5 in conversation