Usage Note 32187: How can I send an email if an error occurs in my log?
An error can be detected using the automatic macro variable SYSCC. SYSCC will indicate that an error has occurred anywhere in the code and its value will remain greater than 0 for the entire job. SYSCC, along with some macro logic and the EMAIL engine in the FILENAME statement can be used to send an email when an error has occurred. In the following example, a character variable is mistakenly listed in the VAR statement.
data a;
input x $ y;
cards;
a 1
b 2
c 3
;
proc means sum;
var x y;
run;
A character variable listed in the VAR statement will generate the following error: ERROR: Variable X in list does not match type prescribed for this list.
This macro can be invoked after PROC MEANS to check the value of &SYSCC and send an email if the value of &SYSCC is greater than 0. The macro uses a DATA _NULL_ with a PUT statement to write the content of the email.
The EMAIL access method available with the FILENAME statement gives you the ability to send an email from SAS. For a complete discussion on this topic, refer to the documentation for this access method: FILENAME Statement: EMAIL (SMTP) Access Method.
data a;
input x $ y;
cards;
a 1
b 2
c 3
;
proc means sum;
var x y;
run;
%macro send_mail;
filename mymail email 'your.name@xyz.com' subject='ERROR in job';
%if &syscc>0 %then %do;
data _null_;
file mymail;
put 'An ERROR has occurred in the code';
run;
%end;
%else %do;
data _null_;
file mymail;
put 'The job ran to completion';
run;
%end;
%let syscc=0;
%mend;
%send_mail
Operating System and Release Information
| SAS System | Base SAS | z/OS | | |
| OpenVMS VAX | | |
| Microsoft® Windows® for 64-Bit Itanium-based Systems | | |
| Microsoft Windows Server 2003 Datacenter 64-bit Edition | | |
| Microsoft Windows Server 2003 Enterprise 64-bit Edition | | |
| Microsoft Windows XP 64-bit Edition | | |
| Microsoft® Windows® for x64 | | |
| OS/2 | | |
| Microsoft Windows 95/98 | | |
| Microsoft Windows 2000 Advanced Server | | |
| Microsoft Windows 2000 Datacenter Server | | |
| Microsoft Windows 2000 Server | | |
| Microsoft Windows 2000 Professional | | |
| Microsoft Windows NT Workstation | | |
| Microsoft Windows Server 2003 Datacenter Edition | | |
| Microsoft Windows Server 2003 Enterprise Edition | | |
| Microsoft Windows Server 2003 Standard Edition | | |
| Microsoft Windows XP Professional | | |
| Windows Millennium Edition (Me) | | |
| Windows Vista | | |
| 64-bit Enabled AIX | | |
| 64-bit Enabled HP-UX | | |
| 64-bit Enabled Solaris | | |
| ABI+ for Intel Architecture | | |
| AIX | | |
| HP-UX | | |
| HP-UX IPF | | |
| IRIX | | |
| Linux | | |
| Linux for x64 | | |
| Linux on Itanium | | |
| OpenVMS Alpha | | |
| OpenVMS on HP Integrity | | |
| Solaris | | |
| Solaris for x64 | | |
| Tru64 UNIX | | |
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.
This code sends an email if an error or warning occurs anywhere in the log.
| Date Modified: | 2021-12-07 15:44:57 |
| Date Created: | 2008-05-21 11:59:44 |