1 / 10

Emailing with SAS

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.

carolinek
Download Presentation

Emailing with SAS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Emailing with SAS How and why to send emails from SAS programs Jerry Le Breton - Softscape Solutions SAUSAG 40 – 19 May 2005

  2. Why use SAS to send emails? • Simple automation for distributing reports • Programmatic / conditional emails • Customised emails SAUSAG 40 – 19 May 2005

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

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

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

  6. Emailing ODS Output • To email ODS output… … it’s trivial. SAUSAG 40 – 19 May 2005

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

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

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

  10. Questions? Jerry Le Breton 0414 513 270 Jerry@SoftscapeSolutions.com.au www.SoftscapeSolutions.com.au SAUSAG 40 – 19 May 2005

More Related