"Especially in the face of large-scale projects, it is necessary to use proc DS2, macro, and FCMP cross-use". I'm with @LinusH here as I don't understand why you think you need to use all three of these together. It would help if you could explain your use case in more detail why these are required.
I too work on large-scale projects and have never found a need to go beyond "normal" macros.
"Embedding a macro definition into the middle of a data step [...] makes no sense." - I dare to dissagre 😉
If you want to create a macro with a "dynamic" name that may be the case:
data _null_;
do i = "A", "B", "C";
rc = resolve('%macro ' !! i !! '(); %put NOTE:[&sysmacroname.];
title "&sysmacroname.";
data &sysmacroname.;
set sashelp.class(obs=3);
run;
proc print;
run;
%mend;');
end;
run;
%A()
%B()
%C()
Bart
I'm using this trick in the MacroArray package (https://github.com/SASPAC/macroarray) to create dynamically named macros which are calling macro array lists.
For example, the `%ABC
` macro is generated automatically inside of %array()
macro:
%array(ABC[17] (111:127), macarray=Y);
%macro test();
%do i = 1 %to 17;
%put &i.) %ABC(&i.);
%end;
%mend;
%test()
%let %ABC(13,i) = 99999;
%do_over(ABC, phrase=%nrstr(
%put &_i_.%) %ABC(&_i_.);
),
which = 1:H:2
);
Bart
The macro pre-processor is for code generation. If you are going to use the data step for the code generation then what is the need for the macro definition? Just generate the code you want instead of trying to generate code that can generate the code you want.
I'm not saying I want to use data step for code generation, I'm just saying that there is a justified use case when inserting macro definition inside a data step makes sense.
The power, or the effect of synergy, from the 4GL and Macro language is that we can "interleave" them. Macro creates data step, data step creates macro, macro calls data step, data step calls macro, and my favourite (from Mike Rhoads' article Use the Full Power of SAS in Your Function-Style Macros) macro calls user defined function which calls a macro. 🙂
Bart
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.