SAS Mfile Capture open code between macro calls

Viewed 50

We can capture macro(%test) executed code with the below snippet

filename mprint 'output-file-name.sas';
options MPRINT MFILE;
%test;
options NOMPRINT NOMFILE;

Is there a way to capture the SAS executed code with MFILE option when we have datasteps/proc calls between the macro calls.

Example:

%test;

data ...
set ...
...
run;

%test2;

proc sort data=...
run;

%test3;

Using some sort of wrapper code to put the above code in a macro and then use MFILE ? Is there any automated standard approach ? I have to implement the solution at enterprise level.

1 Answers

If you have control over the code itself, then you can do it easily using either:

  • Alternate logging methods for the entire SAS log (proc printto, altlog startup option)
  • Wrap the entire code in a macro, then use options mfile

That requires you being able to edit the code, though. Given you've thought of the second, and are asking how, I assume you probably don't have control directly.

If you do not have control over the code but have control over the SAS system (for example, you're a SAS Administrator), then you have a few options, all related to capturing the entire log.

  • You can, again, use altlog option
  • Better, though, is the more advanced logging options using the SAS logging facility. This can be used to put pretty detailed logs from the workspace server, or even from base SAS itself if you're in an environment where users run base SAS interactively.

If you are using a SAS Workspace Server (Enterprise Guide, SAS Studio), then the latter option is very easy: you just need to change the Workspace Server's logging level to Debug, and modify the name of the file it outputs to such that you can make use of it (add to the name things like the username).

Do note that options mfile can be overridden by the user, unless you add it to the restricted options table.

Related