Personal tools
You are here: Home Software Packages SAS Handy SAS programs Email Notification from SAS

Email Notification from SAS

A short macro that will send email from your SAS job.

If you have a long running SAS job, rather than constantly checking to see if it is finished, you can have SAS sent email when the job is finished. This will also work after data steps or procedures within the program.
Here is a simple macro called "sendmail", which is contained in a file email-notify.sas.

/*******************************************************************************

This macro when invoked in a SAS program, will
send an email message indicating that the program/data
step/procedure ended.



Used as is, the condition code, the name of the process, system job id,
and the time and date the job started.



"put" statements can be added, deleted or change to customize the body
of the email message.



To invoke the macro, enclose each emailaddress with quotes, separating
each with a blank, and enclosing the subject with quotes.



Example %mailnote(TOLIST="me@mymail.com",SUBJECT="Macro Use");

or

Example %mailnote(TOLIST="user1@email.com""user2@email.com",
SUBJECT="Example of using macro",
CCLIST="xyz@abc.com" "wxy@abc.com");

*******************************************************************************/



%macro mailnote(TOLIST=,SUBJECT=,CCLIST=);

filename mail_ EMAIL TO=(&TOLIST) SUBJECT=&SUBJECT
CC=(&CCLIST);

data _null_;

file mail_;

put "Job number &SYSJOBID submitted by &SYSUSERID at &SYSTIME on &SYSDATE9 has completed." /;

put "The source file was: &SYSPROCESSNAME";

put " -- ""DMS process"" indicates interactive SAS job submission." ;

put " -- If running a batch job, the name of the file containing the source code " ;

put " will be preceeded by the word ""Program"" "/ ;

put "The condition code returned was: &SYSCC" /;

put "For unix/linux batch jobs, a condition code of:";

put " 0 indicates no errors,";

put " 4 indicates warnings were generated,";

put " and anything higher indicates an error in the program.";

run;
%mend mailnote;


To run the code, include the macro code in your program using a "%inc <filename>". At the end of the job, or after any data steps or procedures in the job, simply invoke the macro with the appropriate parameters.

Upon completion of the job, the recepient should receive an email message which resembles this:
-----------------

Job number 19099 submitted by don at 15:35 on 20FEB2008 has completed.


The source file was: Program testing.sas

-- "DMS process" indicates interactive SAS job submission.

-- If running a batch job, the name of the file containing the source code

will be preceeded by the word "Program"


The condition code returned was: 0


For unix/linux batch jobs, a condition code of:

0 indicates no errors,

4 indicates warnings were generated,

and anything higher indicates an error in the program.
--------------

So if your SAS job takes hours or days to run, you might want to try this notification method.

Note that this will only work on machines with email capability. A secured machine with no internet access or restricted communications may not be able to utilize this.

Document Actions

Copyright ©2008, The Pennsylvania State University | Privacy and Legal Statements
Contact the Help Site Administrator | Last modified Aug 13, 2008 | Weblion Partner