Thursday, March 29, 2012

Sending email through SAS

Today we will learn how to send mail though SAS. Below I have mentioned only method and we will come up with new methods very soon.

Small description about this method:
Below program will send an mail to respective user with log file attached and report of "failure or success of program".


Method 1: DATA STEP

FILENAME MYLIB EMAIL 'myname@mysite.com' EMAILID = "Microsoft Outlook" ;

DATA _NULL_ ;
IF &SYSERR = 0 THEN DO ;
FILE MYLIB
TO='abc@mysite.com'
SUBJECT= 'TEST: Log file for review'
ATTACH= ('C:\My Folder\LOG FILES\TEST.log') ;
PUT 'Hi,' ;
PUT ' ' ;
PUT 'Attached you will find the sas log ready for your review.' ;
PUT ' ' ;
PUT 'Thanks,' ;
PUT 'Aniruddha' ;
END ;
ELSE DO ;
FILE MYLIB
TO='abc@mysite.com'
SUBJECT= 'TEST: Error in Log file' ;
ATTACH= ('C:\My Folder\LOG FILES\TEST.log') ;
PUT 'Hi,' ;
PUT ' ' ;
PUT 'ATTENTION PLEASE!' ;
PUT 'There was an error when this program ran.' ;
PUT 'Please check the program and resubmit.' ;
PUT ' ' ;
PUT 'Thanks,' ;
PUT 'Aniruddha' ;
END ;
RUN ;

/*****************************************************************************************
We may receive an message as below:

A program is trying to automatically send e-mail on your behalf.
Do you want to allow this? If this is unexpected, it may be a
virus and you should choose "No".

To Overcome this message visit: http://support.sas.com/kb/5/335.html
*****************************************************************************************/

Reference: SUGI 29- Automated distribution of SAS® results, by Jacques PagĂ©, Les Services Conseils HARDY, Quebec, Qc

NOTE: Thanks to Google!

Hope this helps you!...