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

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

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.

The Boston Area SAS Users Group is hosting free webinars!
Next up: Joe Madden & Joseph Henry present Putting Power into the Hands of the Programmer with SAS Viya Workbench on Wednesday Nov 6.
Register now at https://www.basug.org/events.

View solution in original post

7 REPLIES 7
JosvanderVelden
SAS Super FREQ
Do you have access to the macro code? Or is it stored in a macro library?
There is a paper on understanding the macro facility that you may want to read: https://support.sas.com/resources/papers/proceedings/proceedings/sugi30/237-30.pdf
JMS
Obsidian | Level 7 JMS
Obsidian | Level 7
The macro source is available.
PaigeMiller
Diamond | Level 26

You can save what MPRINT shows. You can do this manually in the LOG window (File->Save) or programmatically by using PROC PRINTTO.

--
Paige Miller
Quentin
Super User

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.

The Boston Area SAS Users Group is hosting free webinars!
Next up: Joe Madden & Joseph Henry present Putting Power into the Hands of the Programmer with SAS Viya Workbench on Wednesday Nov 6.
Register now at https://www.basug.org/events.
JMS
Obsidian | Level 7 JMS
Obsidian | Level 7

Thanks, MFILE works perfectly!

 

Tom
Super User Tom
Super User

@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 ;

JMS
Obsidian | Level 7 JMS
Obsidian | Level 7
%put %bquote(%mymacro);

 

This is interesting! Thanks!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1516 views
  • 2 likes
  • 5 in conversation