Jedi SAS Tricks: Email from the Front - Part 1

6

I’m responsible for a SAS program that runs nightly in batch on a Linux server here at SAS. I am also a road warrior, and routine status checking via a remote connection is often tricky, and sometimes impossible due to unstable hotel internet connections. So I thought “Why can’t SAS just email me a report of how things went? After all, can’t SAS do most anything?” With my DEV environment along for the ride on my trusty laptop, I popped the top and set about teaching my SAS-code minions to report in.

My first stop was the SAS Online Docs for a review of the FILENAME Statement, EMAIL (SMTP) Access Method topic. Encouraged by the presence of sample code (I love sample code!) I performed my first experiment. It looked something like this:


filename mymail email "SASJedi@example.com" 
         subject="Testing-Windows defaults " lrecl=256; 
data _null_; 
   file mymail; 
   put 'Emailing from SAS is fun!'; 
   put 'Stay SASy!'; 
   put 'Mark'; 
run; 


And up popped my first surprise: Windows detected that SAS was trying to send email and – I’m sure as part of an effort to prevent SPAM sent on my behalf by malware – insisted that I click a button before the email would be sent. I understood that this would NOT be the default behavior on Linux, but decided to investigate anyway. It all boiled down to setting the proper EMAIL options in SAS.  I recorded this video tip (about 6 minutes long) documenting my progress as I use the Force (well, the SAS OPTIOINS, anyway) to control the way SAS sends email.

The SAS code used in the video is included at the bottom of this post (because I'm betting you love sample code as much as I do!)

Now that I’ve got SAS sending email as expected using SMTP, in my next blog entry I’ll tackle creating “pretty” email (using HTML) and sending out emails with attachments.

Until next time, may the SAS be with you.
Mark
Emailing from SAS ZIP file

Share

About Author

SAS Jedi

Principal Technical Training Consultant

Mark Jordan (a.k.a. SAS Jedi) grew up in northeast Brazil as the son of Baptist missionaries. After 20 years as a US Navy submariner pursuing his passion for programming as a hobby, in 1994 he retired, turned his hobby into a dream job, and has been a SAS programmer ever since. Mark writes and teaches a broad spectrum of SAS programming classes, and his book, "Mastering the SAS® DS2 Procedure: Advanced Data Wrangling Techniques" is in its second edition. When he isn’t writing, teaching, or posting “Jedi SAS Tricks”, Mark enjoys playing with his grand and great-grandchildren, hanging out at the beach, and reading science fiction novels. His secret obsession is flying toys – kites, rockets, drones – and though he usually tries to convince Lori that they are for the grandkids, she isn't buying it. Mark lives in historic Williamsburg, VA with his wife, Lori, and Stella, their cat. To connect with Mark, check out his SAS Press Author page, follow him on Twitter @SASJedi or connect on Facebook or LinkedIn.

6 Comments

    • SAS Jedi

      Nice! I really liked the detailed, step-by-step instructions you've put together for scheduling SAS jobs to run unattended on Windows.

  1. I use a similar approach to have SAS send me text messages as various stages of long-running jobs are completed. (With my particular smart-phone and its settings, text messages are more instantaneous than having to manually poll for new emails periodically...especially afterhours when I'm away from my desk.) Instead of having SAS send a message to my standard work email or personal email, I use the SMS gateway address that sends email as a text message to my phone -- "3035551212@pm.sprint.com". Most carriers have SMS gateways for text-via-email -- http://en.wikipedia.org/wiki/List_of_SMS_gateways

  2. This is wonderful, but how can one do this if one's system uses exchange instead of SMTP to send email?

Back to Top