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.

BASUG is hosting free webinars Next up: Mike Raithel presenting on validating data files on Wednesday July 17. Register now at the Boston Area SAS Users Group event page: 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.

BASUG is hosting free webinars Next up: Mike Raithel presenting on validating data files on Wednesday July 17. Register now at the Boston Area SAS Users Group event page: 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!

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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