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 webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.

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 webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
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: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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
  • 1650 views
  • 2 likes
  • 5 in conversation