07-03-2013 05:35 AM
How to email SAS logs through code in a Scheduled EG project?
I would like to automate the process of sending the SAS log when the scheduled job execute. Is there a way in EG or should I create a code using VB?
07-03-2013 09:54 AM
It is pretty easy to do that in EGuide. First, you have to set up your environment (for me, finding the name of your outgoing SMTP server was the hardest part). In EG 5.1, that is under tools --> options --> Administration .
Then run your task and select something that you want to send by right-clicking on the icon and selecting "send to" and "email recipient as a step in the project". Once in that task, you can select the specific log's and other objects that you want to e-mail.
09-12-2014 05:24 AM
No, Doc@Duke, Hashim Basheer wants a totally automated process. He wants the scheduled EG project to email the SAS log without manual intervention at end of processing.
Here is the code to do it, and also, if desired, to email procedure output, in two different formats, as well. With arrival of ODS, one probably would not really bother to use the PROC PRINTTO PRINT= option.
proc printto log="C:\temp\SAS_log_from_EG_processing.txt" new; run;
proc printto print="C:\temp\SAS_procedure_output_from_EG.txt" new; run; /* this automatically opens the LISTING destination, if not already open */
ods pdf notoc file="C:\temp\SAS_procedure_output_from_EG.pdf";
proc print data=sashelp.class; run;
ods pdf close;
proc printto; run;
filename anyname email
subject="Sending an EG SAS log and SAS procedure output via email from SAS EG"
attach=("C:\temp\SAS_log_from_EG_processing.txt" "C:\temp\SAS_procedure_output_from_EG.txt" "C:\temp\SAS_procedure_output_from_EG.pdf");
put 'This is an email sent by SAS EG';
put 'Attached are the SAS log and two forms of the procedure output from prior SAS processing';
07-04-2013 12:04 PM
Use PROC PRINTTO to route the SAS log for the main body of your code to a disk file.
After the closing PROC PRINTTO; RUN;
include the code to email that disk file to the desired recipient(s).
09-12-2014 05:59 AM
You are right Leroy, but do not forget to mention the email settings must be configured well in your running SAS session and there should be no firewalls blocking.
The proc printto log will work I would prefer a scheduled task having running as batch and stored tat log-file already. Sending that as attachment should be easy.
Automation with EGuide is more adhoc work not really professional automation.
09-12-2014 08:15 AM
If you want to use SAS code to send an e-mail message, this paper is a good reference with examples:
But if you simply want to capture an e-mail step in an EG project that you already schedule, you can either:
- use Send To->E-mail recipient as a step from the content that you want to send (such as a log). This will send e-mail every time your process is run, whether running interactive or as a scheduled job.
- Add an e-mail step in the automation script you're using to run your scheduled project. This will run only as part of your script, and not as part of the project when run interactively.
The Send To (as a step) looks like this:
Resulting in a flow like this:
If using script, you can use the built-in SendMail method available on most result objects. However, this triggers a MAPI (Outlook) e-mail that might not work well with security settings. Or use can use VBScript objects to craft/send whatever message you want via SMTP (which is how the E-mail as a Step process works in EG). Here's a script example from stackoverflow.
09-12-2014 01:30 PM
Glad to see that my much belated follow-up to Doc@Duke's second response to Hashim Basheer has sparked more discussion.
Before I get to my main points, I should mention that I don't understand why this environment imbedded those envelope icons before each email address in my FILENAME statement above. They are not part of the correct syntax.
Jaap, Yes, I understand that the environment needs to be set up to permit email to be sent from the SAS machine.
Chris, I had not seen Chuck Hunley's paper
"SMTP E-Mail Access Method: Hints, Tips, and Tricks"
For more on how to do things with SAS for email, there is an excellent trilogy of SAS Global Forum papers by Erik Tilanus, plus his most SGF paper. Find them at:
"Sending E-mail from the DATA step"
"Using the DATA step as a POP3 mail client"
"The Trilogy on e-Mailing, Part 3: Handling e-Mail Attachments with SAS®"
"Using Mail Functionality in SAS"
My own contribution to the topic of SAS-sent email was:
"SAS® Graphs for a BlackBerry, iPhone, or Other Small Email Screen: Extreme SAS/GRAPH® and the Necessity and Power of Simplicity"
In 2008 and years thereafter, it was only possible to send SAS graphs as email attachments (despite a defective example for imbedded graphs in the SAS documentation).
For what's NOW possible, see two recent blog postings by Robert Allison:
"SAS 9.4 has a new way to send interactive graphs in email!"
"Easy new way to send drilldown graphs in an email"