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?
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.
Doc Muhlbaier
Duke
Thanks Duke. As I am scheduling the Project to run on a daily basis, I would like to automate the process.
That's exactly what the steps I outlined will do for the project logs.
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
to="le_roy_bessler@wi.rr.com"
from="bessler@wi.rr.com"
sender="bessler@wi.rr.com"
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");
data _null_;
file anyname;
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';
run;
very good
but where i can set e-mil password
The example code supplied runs on a PC where the email client uses Windows Authentication to access so no user/password is required. If your requirements are different please let us know what they are.
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).
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.
If you want to use SAS code to send an e-mail message, this paper is a good reference with examples:
http://support.sas.com/resources/papers/proceedings10/060-2010.pdf
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.
Chris
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"
http://support.sas.com/resources/papers/proceedings10/060-2010.pdf
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"
http://www2.sas.com/proceedings/forum2008/038-2008.pdf
"Using the DATA step as a POP3 mail client"
http://support.sas.com/resources/papers/proceedings09/002-2009.pdf
"The Trilogy on e-Mailing, Part 3: Handling e-Mail Attachments with SAS®"
http://support.sas.com/resources/papers/proceedings11/429-2011.pdf
"Using Mail Functionality in SAS"
http://support.sas.com/resources/papers/proceedings13/023-2013.pdf
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"
http://www2.sas.com/proceedings/forum2008/034-2008.pdf
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"
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.