Sending an email from SAS

This post was kindly contributed by AFHood Analytics Group - Blogs » SAS - go there to comment and to read the full post.

Have you ever wanted to know when your code completes? Or maybe you want to automate the report to include sending an email?

Regardless, SAS is happy to send that email for you. The easiest way to do this is through the SMTP access method via filename statements.

Example:

filename sendemail email ‘toaddress@email.com’ subject=’This is a test email.’ from=’fromaddress@email.com’;

data _null_;

file sendemail;

put ‘Hi,’;

put ‘This is a email sent from SAS’;

run;

This is only a simple example. Here is another with an attachment.

filename sendemail email ‘toaddress@email.com’ subject=’This is a test email.’ from=’fromaddress@email.com’ attach=’/somesascode.sas’;

data _null_;

file sendemail;

put ‘Hi,’;

put ‘This is a email sent from SAS’;

run;

Email attributes can also be set in the data step through the EM_ directives.

filename sendemail email ‘toaddress@email.com’ ;

data _null_;

set somedataset;

put ‘!EM_TO! ‘ email_addr;

put ‘!EM_SUBJECT! ‘ subscription_name;

put name ‘ ,’;

put ‘This message was generated by a SAS data set’;

put ‘!EM_SEND!’;

run;

This post was kindly contributed by AFHood Analytics Group - Blogs » SAS - go there to comment and to read the full post.