BookmarkSubscribeRSS Feed
HashimBasheer
Fluorite | Level 6

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?

10 REPLIES 10
Doc_Duke
Rhodochrosite | Level 12

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

HashimBasheer
Fluorite | Level 6

Thanks Duke. As I am scheduling the Project to run on a daily basis, I would like to automate the process.

Doc_Duke
Rhodochrosite | Level 12

That's exactly what the steps I outlined will do for the project logs.

LeRoyBessler
Obsidian | Level 7

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;

abdelrahman
Calcite | Level 5

very good
but where i can set e-mil password

SASKiwi
PROC Star

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. 

LeRoyBessler
Obsidian | Level 7

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).

jakarman
Barite | Level 11

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.

---->-- ja karman --<-----
ChrisHemedinger
Community Manager

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:

emailstep.PNG

Resulting in a flow like this:

emailflow.png

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

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
LeRoyBessler
Obsidian | Level 7

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!"

http://blogs.sas.com/content/sastraining/2013/11/06/sas-9-4-has-a-new-way-to-send-interactive-graphs...

"Easy new way to send drilldown graphs in an email"

http://blogs.sas.com/content/sastraining/2014/01/22/easy-new-way-to-send-drilldown-graphs-in-an-emai...

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 11220 views
  • 8 likes
  • 7 in conversation