Did you ever want the log file from a SAS batch job to be saved with the date and time that the job ran and/or be e-mailed to a recipient or group of recipients. At least for Windows/SAS environments, here's the secret below:
Set up a SAS program that gets called from a batch file that gets called from each batch file that runs a SAS program. It should look something like the following:
/* Set two SAS macro variables from environment variables */
%let
sasmail=%sysget(sasmail);%let
saslog=%sysget(saslog);Filename
OUTBOX EMAIL ' ' ; /* Set up filename for email */Data
_null_ ;File
OUTBOX /* Use Filename defined above */TO=(&sasmail)
/* Get recipient address */Attach=(
"&saslog") /* Attach the log file */Subject=
"Log file &saslog"; /* Add a subject */Put
"SAS log file is attached" ; /* Goes in the body */Run
;Set up a batch file to call the above SAS program. It should look something like the one below:
rem Put actual email address of recipeint(s) below
set sasmail="you@email.com" "another@email.com"
rem Copy the original sas log to one that has the date and time
appended (for future reference)
copy "%saslog%"
"%saslog%%date:~-4,4%-%date:~-10,2%-%date:~-7,2%-%time:~-11,2%%time:~-8,2%%time:~-5,2%.log"
rem Call the sas process that emails the above log as an attachemnt
to the email address(ees) above.
"D:\SAS\SAS 9.1\sas.exe" "F:\SAS ETL Jobs\sendemail.sas" -config
"D:\SAS\SAS 9.1\nls\en\SASV9.CFG"
-log "F:\SAS
ETL Jobs\logs\sendemail.log"
In each of the SAS bat files that call .sas programs, insert two lines:
An example follows:
rem This process run the SAS process in batch suitable for scheduling
That's it. Enjoy