- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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