/*** THESE ARE THE BASIC ELEMENTS REQUIRED TO RUN E-MAIL DISTRIBUTIONS IN SAS PROGRAMS. NOTE THAT CERTAIN SETTINGS MUST BE ADDED TO THE CONFIG FILE TO ACTIVATE THIS FUNCTION IN YOUR SAS INSTALLATION. ***/ /************************************************************/ /*** 1ST: ****/ /************************************************************/ /*** ADD THE FOLLOWING SETTINGS TO YOUR SAS CONFIG FILE TO ACTIVATE E-MAIL **/ /** e-mail parameters ****/ -EMAILSYS SMTP -EMAILDLG NATIVE -EMAILHOST gateway_server_name_here /** Optional parameter: emailport. Most e-mail systems naturally use PORT 25, and that is the default which SAS assumes unless it's told otherwise. If your enterprise uses a different port for e-mail communications use the following format to specify that port: */ -EMAILPORT 25 /************************************************************/ /************************************************************/ /*** 2ND: ****/ /************************************************************/ /*** Create a separate variable to hold target e-mail ID. Use a group ID's set up in your enterprise e-mail. Comment this out until the system is functioning. */ /* %let egrp = TRNS_PES_chek ; */ /************************************************************/ /************************************************************/ /*** 3RD: ****/ /*** !!!!!!! MOST IMPORTANT STEP IN THE PROGRAM !!!!!! ****/ /*** !!!!!!! MOST IMPORTANT STEP IN THE PROGRAM !!!!!! ****/ /*** !!!!!!! MOST IMPORTANT STEP IN THE PROGRAM !!!!!! ****/ /************************************************************/ /* AIM THE RESULTS AT A "TEST" E-MAIL GROUP THAT ONLY COMES BACK TO YOU. YOU'LL WANT ALL E-MAILS COMING BACK TO YOU UNTIL YOUR'RE ABSOLUTELY SURE THINGS ARE FUNCTIONING PROPERLY. *************************************/ %let egrp = TEST ; /************************************************************/ /************************************************************/ /*** 4TH: ****/ /************************************************************/ /*** Use the filename statement to set up the addresses to use in the enterprise e-mail system. You need to populate the "from" the "to" and the "sender." The sender field must be populated for it to work, though the sender doesn't need to be the same as the "from" field. Note: Version 8.2 and some Version 9 SAS installations require you to download a patch from the SAS website to activate the "sender=" function. Your e-mails won't work without having a properly functioning "sender=" function. The patch is self-installing and relatively painless to implement, once you determine which patch pertains to your installation. Call The SAS Institute at (919)677-8008 for assistance. */ filename mailout EMAIL sender="Custom TRNS*PORT reports" from="turner.bond@modot.mo.gov" to=("&egrp" ) ; /************************************************************/ /************************************************************/ /*** 5TH: ****/ /************************************************************/ /*** CREATE A DIRECTORY IN WHICH TO STORE YOUR ATTACHMENTS. ***/ options noxwait noxsync ; /*** When calling the operating system (OS) close the OS window and don't wait for OS functions to complete before moving on. */ /* Create the directory. If it already exists, this code will not affect the direectory. */ X %UNQUOTE(%STR(%'MD "&storplac\LETTING\&Nletyear\&Nlettag"%')) ; /**** GATHER, PROCESS AND CREATE YOUR DATA ******/ /**** GATHER, PROCESS AND CREATE YOUR DATA ******/ /**** GATHER, PROCESS AND CREATE YOUR DATA ******/ /**** GATHER, PROCESS AND CREATE YOUR DATA ******/ /**** GATHER, PROCESS AND CREATE YOUR DATA ******/ /**** GATHER, PROCESS AND CREATE YOUR DATA ******/ /**** GATHER, PROCESS AND CREATE YOUR DATA ******/ /************************************************************/ /************************************************************/ /*** 6TH: ****/ /************************************************************/ /**** Wrap your output in ODS statements to create your results in a file format that can be attached to an e-mail. In this case it's an HTML file. Format varies with file type. I.E. PDF's use "file=" instead of "body=", etc. ***/ ods html body="&storplac\LETTING\&Nletyear\&Nlettag\&Nlettag._PESnodistrERR.htm" style = SASweb ; /* html functions */ proc print data=PMISSDIS noobs label ; title1 "PES Errors in Letting of &prntnextdate" ; title2 "Proposals with No District Data" ; var contid ; label contid = "Proposal ID"; run ; ods html close ; /************************************************************/ /************************************************************/ /*** 7TH: ****/ /************************************************************/ /*** SEND RESULTS TO DESIGNATED E-MAIL GROUP */ data _NULL_ ; file mailout /**** link to the filename statement above for addressing ***/ /*** establish subject text and attachments. Note that there are no commas. Attachments are qouted and separated by a space. Attachment text msut be <= 256 chsaracters. **/ subject= "&Nlettag errors in PES" attach=( "&storplac\LETTING\&Nletyear\&Nlettag\&Nlettag._PESnostaffERR.htm" "&storplac\LETTING\&Nletyear\&Nlettag\&Nlettag._PESnobidERR.htm" "&storplac\LETTING\&Nletyear\&Nlettag\&Nlettag._PESnocntyERR.htm" "&storplac\LETTING\&Nletyear\&Nlettag\&Nlettag._PESnodistrERR.htm" "&storplac\LETTING\&Nletyear\&Nlettag\&Nlettag._PESnotypeERR.htm" ); /*** Create the text of your e-mail using put statements. The sky is the limit here. You can enclose the whole data _NULL_ in macro code and make conditional text for the email, based on condtions. You can include macro variables. Note that each put statement creates a separate paragraph. ****/ put ; put "Attached are errors and/or warnings associated with PES data for the projects MoDOT is letting on &prntnextdate.. Please review the attached errors and modify the fields as needed." ; put ; put ; run ;