I have SAS programs here which are very old and consist of more macro code than sas code. There are hundreds of macros and the nesting level is mor than 5. The main purpose of the macros is to construct statements for the data step. The code of the macros is available as source. It is so much macro code that it is not visible what the code does. Is it possible to save the SAS code after the macro processor did its work? Similar to what MPRINT shows? Would it be possible to write a statement-style macro and name it "data", together with the "implmac" option?
You might want to look into MFILE, in addition to MPRINT. See e.g. https://blogs.sas.com/content/sgf/2022/12/21/decode-your-sas-macro-code/
The thought of an old-style percent-less macro hijacking the DATA statement is pretty scary. I think I vaguely remember someone saying their site used an old-style macro to hijack the LIBNAME statement, so it might be possible.
I don't know know if MPRINT / MFILE even know about the percent-less macros.
You can save what MPRINT shows. You can do this manually in the LOG window (File->Save) or programmatically by using PROC PRINTTO.
You might want to look into MFILE, in addition to MPRINT. See e.g. https://blogs.sas.com/content/sgf/2022/12/21/decode-your-sas-macro-code/
The thought of an old-style percent-less macro hijacking the DATA statement is pretty scary. I think I vaguely remember someone saying their site used an old-style macro to hijack the LIBNAME statement, so it might be possible.
I don't know know if MPRINT / MFILE even know about the percent-less macros.
Thanks, MFILE works perfectly!
@JMS wrote:
I have SAS programs here which are very old and consist of more macro code than sas code. There are hundreds of macros and the nesting level is mor than 5. The main purpose of the macros is to construct statements for the data step. The code of the macros is available as source. It is so much macro code that it is not visible what the code does. Is it possible to save the SAS code after the macro processor did its work? Similar to what MPRINT shows? Would it be possible to write a statement-style macro and name it "data", together with the "implmac" option?
Look at MFILE also.
Or just print it your self:
%put %bquote(%mymacro);
Example:
1031 %macro mymacro(varname); 1032 &varname = &varname ** 2 ; 1033 %mend; 1034 1035 %put %bquote(%mymacro(x)); x = x ** 2 ;
%put %bquote(%mymacro);
This is interesting! Thanks!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.