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?
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.
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.
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.
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.
@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
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: