100 likes | 117 Views
Emailing with SAS. How and why to send emails from SAS programs. Jerry Le Breton - Softscape Solutions. Why use SAS to send emails?. Simple automation for distributing reports Programmatic / conditional emails Customised emails. FILENAME Statement is the Key. Special EMAIL device type.
E N D
Emailing with SAS How and why to send emails from SAS programs Jerry Le Breton - Softscape Solutions SAUSAG 40 – 19 May 2005
Why use SAS to send emails? • Simple automation for distributing reports • Programmatic / conditional emails • Customised emails SAUSAG 40 – 19 May 2005
FILENAME Statement is the Key Special EMAIL device type • filename mail email “jerry@softscape.net.au" subject="Party Invite"; attach="c:\pictures\wildparty3.jpg"; data_null_; file mail; put"Hi Jerry,"; put"The IT department is holding another of its wild parties on Friday."; put"It was the talk of the town last year. Pity you couldn't make it."; put"Attached is a picture from last time - so you can prepare yourself!"; put"Cheers, Doug"; run; Various options for sending emails SAUSAG 40 – 19 May 2005
Controlling Emails in the Data Step FILE statement options override those on the FILENAME statement filename mail email"jerry@softscape.net.au" subject="Party Invite" attach="c:\pictures\wildparty3.jpg"; data_null_; file mail to=(“sandy@softscape.net.au""alan@softscape.net.au") cc="jerry@softscape.net.au" subject="Wilder Party Invite" attach="c:\pictures\wildparty4.jpg"; put"Hi Sandy and Alan,"; put"Sorry - of course you're invited too."; put"Attached is an even better picture from last time."; put"Make sure the kids aren’t looking over your shoulder!"; put"Cheers, Doug"; run; SAUSAG 40 – 19 May 2005
Customising Emails from the Data Step • Special email “directives” enable filename options to be overridden / changed, for each Data step iteration. filename mailout email"nul" ; data_null_; set emaillist end=theend; retain subject 'Remember: The Wild Party is Tonight'; file mailout ; put'!EM_TO!' emailid; /* The TO address is on the input data set */ put'!EM_SUBJECT!' subject; /* Overrides FILE and FILNAME specification */ put'Hi ' firstName ; /* Insert first name into first line */ /* Put the main body of the email ... */ put / "Remember the IT Department's Wild Party starts at 7.00pm tonight." // "Be warned - it'll go late (at least 9.00)." // "Doug"; put'!EM_SEND!'; /* Send the email now */ put'!EM_NEWMSG!'; /* Clear current email attributes */ if theend then put'!EM_ABORT!'; /* Stops auto send at end of Data step */ run; SAUSAG 40 – 19 May 2005
Emailing ODS Output • To email ODS output… … it’s trivial. SAUSAG 40 – 19 May 2005
Emailing ODS Output The FILENAME statement does it all. Note the TYPE option for sending html. • Send HTML output directly to an email: • /* Sample program sending Proc output to an email address */ filename outfile email subject= "Sales Summary" from = "jerry.lebreton@afp.gov.au" to = "jerry@softscape.net.au" type = "text/html"; odshtmlbody=outfile; title j=left " Total Sales by Country and Product"; proctabulatedata =sashelp.prdsale f=dollar10.missing style=[background=beige]; class prodtype / style=[foreground=blue]; class country / style=[foreground=green]; var actual ; table country all*[style=<parent>[background=white font_weight=bold]], prodtype*actual=''; keylabel sum=' '; keyword all / style=[font_weight=light font_style=italic foreground=red]; run; odshtmlclose; For all emails these options need setting in the config file : • -emailsys smtp • -emailhost your.smtp_server.host SAUSAG 40 – 19 May 2005
SAS and other emailers • Can use other email programs e.g. smtpsendutility (no client e.g. Outlook) data_null_; call system("smtpsend -hsmtp.softscape.net.au -f&fromid -t&toid -sFooty Update Log -ic:\footy\error_report.txt -ac:\footy\weekend_update.log"); run; host from to subject include(d text) attachment SAUSAG 40 – 19 May 2005
So… • Emailing from SAS is one more way to • Automate distribution of reports • Customise results • Target output. • References: • V8 OnlineDoc: Base SAS Software / Host Specific Information / Windows Environment / Using Groupware to Distribute SAS Data / Sending Electronic Mail • Automated distribution of SAS results – Jacques Page www2.sas.com/proceedings/sugi29/039-29.pdf SAUSAG 40 – 19 May 2005
Questions? Jerry Le Breton 0414 513 270 Jerry@SoftscapeSolutions.com.au www.SoftscapeSolutions.com.au SAUSAG 40 – 19 May 2005