I have a process in SAS with many data steps. I want to check the return code (rc) after which data step processing and if the rc is different to 0 then the system sends a e-mail with the code and message of error. How may I do this?
various return and status codes for SAS are available through predefined macro variables:
SYSERR, SYSFILRC, SYSLIBRC, SYSRC, SYSCC
SYSERR = "Contains a return code status set by some SAS procedures and the DATA step"
Check your SAS Macro Language Reference documentation for detailed descriptions.
Email is more involved, but can be done, I believe via the ODS system. I believe it requires an email account, password, access/knowledge of the email server. But, once set up , it is easy to compose and send an email from within SAS.
Message was edited by: Chuck
There are many resources to tell you how to send email from a SAS session, and you would do well to read widely among the available notes and papers.
A couple of traps are out there however. The first is that if you try to do something in a data step that causes a SAS error, like reference a file that doesn't exist, then SAS will set Obs to 0 and go into debugging mode. As a result, any subsequent step that tries to process data; like a Data _NULL_ to send an email, will not work. Be careful of the system return codes too, make sure you understand how each one works, and where it will not tell you what you think it does. Carefully Read The Factual Material.
The second issue to consider is the problem(s) caused by using an email client such as Outlook to send your email. Not only will you probably encounter their puerile "A program is trying to send email" message box, but you are prone to have your email address "Interpreted" by the Outlook address book. The general solution is to use SMTP to send the email but this opens some security issues with the Post Office, and is often not allowed by your system administrators.
You can solve each of these problems, but be aware that it may not be, or remain simple.