Search notes:

log related SAS macros

redirectLog

%tq84_redirectLog uses proc printto to redirect the output of the log file and procedure output.
I especially needed this functionality when working with Enterprise Guide.
The width of the output is set to the maximum of 256 characters.
The filename looks like YYYY-MM-DD_HH-MM-SS-PID (PID is the process identifier as identified with &sysobjid.
%macro tq84_redirectLog(logDir);
   options linesize=256
           nocenter    /* Setting nocenter so that output of proc sql is put to left side */
   ;

   %local logFile;
   %let   logFile="&logDir/%sysfunc(putn(%sysfunc(date()), yymmddd10.))_%tq84_reReplace(%sysfunc(putn(%sysfunc(time()), tod8.)), :, -)_&sysjobid";

/* The order of the proc printo is important
  (https://stackoverflow.com/a/47515843/180275) */
   proc printto log   = &logFile; run;
   proc printto print = &logFile; run;

%mend  tq84_redirectLog;
Github repository about-SAS, path: /macros/log/redirectLog.sas
See also highlight-sas-log.pl
In order for the log file to be immediately flushed, the logparm option should be set to write=immediate in a config file.

Index