Stamping the SAS Log with all Macro Variable Values

This post was kindly contributed by ProcRun; - go there to comment and to read the full post.

The topic of the day around the office was stamping all of the user created macro variables into the log function. I’ve got a few programs that have a lot (20+) auto-generated dates, etc and the following is just one of the the many ways to print what each macro resolves to into your log file.

Code:

data _null_;
  y = today();
  x = intnx('month',y,-1);
  call symput('prev_month',strip(put(x,monname9.)));
  call symput('today',put(y,yymmddn8.));
run;

data _null_;
 set sashelp.vmacro;
 where value > "" and scope = "GLOBAL"
       and substr(name, 1, 3) not in ('SQL','SYS');
 put "Macro Variable: " name  "resolves to: " value;
run;

Output into the Log File:

1    data _null_;
2      y = today();
3      x = intnx('month',y,-1);
4      call symput('prev_month',strip(put(x,monname9.)));
5      call symput('today',put(y,yymmddn8.));
6    run;
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.00 seconds

7   data _null_;
8    set sashelp.vmacro;
9    where value > "" and scope = "GLOBAL"
10          and substr(name, 1, 3) not in ('SQL','SYS');
11   put "Macro Variable: " name  "resolves to: " value;
12  run;

Macro Variable: PREV_MONTH resolves to: March
Macro Variable: TODAY resolves to: 20120403
NOTE: There were 2 observations read from the data set SASHELP.VMACRO.
      WHERE (value>' ') and (scope='GLOBAL') and
      SUBSTR(name, 1, 3) not in ('SQL', 'SYS');
NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.01 seconds

The where clause of the second data step can be edited to include the SQL and SYSTEM macro variables if need be and / or the scope can be change to print just the local macro variables with a macro (if you put the code inside of the macro).

This post was kindly contributed by ProcRun; - go there to comment and to read the full post.