ing with SAS – Jerry Le Breton, Softscape Solutions SAUSAG 40 – 19 May ing with SAS How and why to send s from SAS programs Jerry Le Breton - Softscape Solutions
ing with SAS – Jerry Le Breton, Softscape Solutions SAUSAG 40 – 19 May 2005 Why use SAS to send s? Simple automation for distributing reports Programmatic / conditional s Customised s
ing with SAS – Jerry Le Breton, Softscape Solutions SAUSAG 40 – 19 May 2005 FILENAME Statement is the Key filename mail 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; Special device type Various options for sending s
ing with SAS – Jerry Le Breton, Softscape Solutions SAUSAG 40 – 19 May 2005 Controlling s in the Data Step filename mail subject="Party Invite" attach="c:\pictures\wildparty3.jpg"; data _null_; file mail 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; FILE statement options override those on the FILENAME statement
ing with SAS – Jerry Le Breton, Softscape Solutions SAUSAG 40 – 19 May 2005 Customising s from the Data Step Special “directives” enable filename options to be overridden / changed, for each Data step iteration. filename mailout "nul" ; data _null_; set list end=theend; retain subject 'Remember: The Wild Party is Tonight'; file mailout ; put '!EM_TO!' id; /* 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 ... */ 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 now */ put '!EM_NEWMSG!'; /* Clear current attributes */ if theend then put '!EM_ABORT!'; /* Stops auto send at end of Data step */ run;
ing with SAS – Jerry Le Breton, Softscape Solutions SAUSAG 40 – 19 May ing ODS Output To ODS output… … it’s trivial.
ing with SAS – Jerry Le Breton, Softscape Solutions SAUSAG 40 – 19 May 2005 Send HTML output directly to an /* Sample program sending Proc output to an address */ filename outfile subject= "Sales Summary" from = to = type = "text/html"; ods html body=outfile; title j=left " Total Sales by Country and Product"; proc tabulate data =sashelp.prdsale f=dollar10. missing style=[background=beige]; class prodtype / style=[foreground=blue]; class country / style=[foreground=green]; var actual ; table country all*[style= [background=white font_weight=bold]], prodtype*actual=''; keylabel sum=' '; keyword all / style=[font_weight=light font_style=italic foreground=red]; run; ods html close; ing ODS Output The FILENAME statement does it all. Note the TYPE option for sending html. For all s these options need setting in the config file : - sys smtp - host your.smtp_server.host
ing with SAS – Jerry Le Breton, Softscape Solutions SAUSAG 40 – 19 May 2005 SAS and other ers Can use other programs e.g. smtpsend utility (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; h ost f rom t o s ubject i nclude(d text) a ttachment
ing with SAS – Jerry Le Breton, Softscape Solutions SAUSAG 40 – 19 May 2005 So… ing 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/ pdf
ing with SAS – Jerry Le Breton, Softscape Solutions SAUSAG 40 – 19 May 2005 Questions? Jerry Le Breton
ing with SAS – Jerry Le Breton, Softscape Solutions SAUSAG 40 – 19 May 2005 Custom s from the Data Step Special “directives” enable filename options to be overridden, for each Data step iteration. filename mailout "nul" data _null_; set list end=theend; retain subject 'Remember SAUSAG today'; file mailout subject="Subject line" ; put '!EM_TO!' id; /* 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 ... */ put / "Remember SAUSAG starts at 4.00pm today." // "See you there." // "Jerry"; put '!EM_SEND!'; put '!EM_NEWMSG!'; if theend then put '!EM_ABORT!'; run;