Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I see the original sas macro code?

Tags:

sas

sas-macro

I'm trying to debug code used in a SAS program, but the program uses macros from a permanent library. I can't find the code that created the macros and I don't have access to the person who created the original library. I know that option mprint; will show me the lines of code that the macro executes, but I would like to see all of the code that a macro uses so that I can more easily debug it. In other words, I would like to have all the information that would be available to me if I had the original program that generated the macros. Is that possible?

like image 462
Sam Dickson Avatar asked Mar 18 '23 08:03

Sam Dickson


1 Answers

There are two possible ways you could be executing a SAS macro from a permanent library. Either you are using an autocall macro, or a stored compiled macro.

An autocall macro would mean you do have access to the source, because it's simply a .sas file with the name of the macro as the name of the file. You can %include the file and see the full text, assuming you know which directory it is in (you can have many autocall libraries). So if your SASAUTOS directory is c:\sas\macros\, and you are calling %mymacro(), then you could execute

%include "c:\sas\macros\mymacro.sas";

which would include the pre-compiled text, and as long as you have the source2 option enabled, it will print to your log.

A stored compiled macro can be viewed only if it was compiled with the SOURCE option. If it was not, then you cannot retrieve the macro source code (without having access to the program that created the SCM).

If it was compiled with SOURCE, then you can use the %COPY macro statement to copy the source code from the SCM to your log:

%copy mymacro / SOURCE;

More details are available in the SAS documentation, or from the excellent paper Ways to Store Macro Source Codes and How to Retrieve Them.

like image 191
Joe Avatar answered Apr 29 '23 20:04

Joe