Category: SAS

Sending Email from within SAS and other options…

Sending Email from within SAS and other options…

FILENAME Statement EMAIL (SMTP) Access Method allows you to send electronic mail programmatically from SAS using the SMTP (Simple Mail Transfer Protocol) e-mail interface available at your site.

But before you process the email code below check the values for the system options using Proc options for EMAILAUTHPROTOCOL, EMAILHOST, EMAILPORT, EMAILID, EMAILPW for your site…They have to have appropriate values for your code to work.

Read more about them @ System Options That Control SMTP E-Mail.

proc options group=email; run;


The Log generated…

59   proc options group=email; run;
    SAS (r) Proprietary Software Release 9.1  TS1M3
 EMAILAUTHPROTOCOL=LOGIN
                   Identifies the SMTP e-mail authentication protocol
 EMAILHOST=xxx.xx.xx.xxx
                   SMTP server host for email access method
 EMAILID=xxxxxx    From E-mail address, log in id, or profile for use with underlying e-mail
                   system
 EMAILPORT=25      Port number for SMTP server for email access method
 EMAILPW=xxxxxxxx  Used by the E-mail Access Method and Send menu item to set the email session
                   login password for the underlying e-mail system
 EMAILDLG=native   Used by Send menu item to set the email dialog interface.
 EMAILSYS=smtp     Used by E-mail Access Method and Send menu item to set the interface type with
                   underlying e-mail system.
Try the following email example for sending an email using SAS data step…replace emails and the attachments as you wish…This example has the most common options that you might use….Please look at the SAS examples in the References (5-7) below for some more advanced methods….
filenameoutbox email “sastechiesblog@gmail.com”;

data_null_

   fileoutbox 

      to=(“sastechiesblog@gmail.com”“info@sastechies.com”

         /* Overrides value in filename statement */ 

      cc=(“info@sastechies.com”“someone@mail.com”

      subject=“My SAS Output” 

      attach=(“C:sasresults.out”“C:sascode.sas”)

   ; 

   put‘Folks,’

   put‘Attached is my output from the SAS’

   put‘It worked great!’;

run;

Here is another way of sending emails using SAS X command in a Unix Environment that has the mailx utility…Sometimes it might just better to use the native operating system utilities rather than using SAS Filename Email Statement…
Here’s a macro that does that for you…
%macroSendEmail;

/*Write the contents to a file */

 data _null_;

   file “&emailfile”lrecl=256;

   %emailbody;

 run;

       

   /* %put to=&to cc=&cc subject=&subj attach=”&attach”; */

  

   /*use the X command and invoke the Unix mailx command */

  

   X “(cat &emailfile;) | mailx -s “”&subj”” &to –c &cc”;

   X ” if [[ $? -ne 0 ]] then echo `date`” “Failed to send email to &to” “else rm ~/&emailfile fi”;

%mendSendEmail;

%letsubj=Hey SASTechies;

%letto=sastechiesblog@gmail.com;

%letattach=;

%letcc=;

%letemailfile=~/email.dat; /* path to the temporary file at home directory (ie. ~) */

%macroemailbody;

  PUT “This is a test message from SASTechies”;

  PUT “This test mail has been generated from SAS Data Step using Native Unix Mail command”;

%mendemailbody;

%SendEmail;

A brief explanation here…

Enter your email/attachment/subject in the macro variables…the &emailfile is a temporary file that SAS writes to compile the email body…This is later deleted if SAS was successful in sending the email…

   X “(cat &emailfile;) | mailx -s “”&subj”” &to –c &cc”;

The unix command cat &emailfile writes the body for the mailx unix command that takes –s option for subject followed by the to and cc options. 

Check the unix man page screenshot below for more options…

sas email

Other References

9.4, What’s New – Becoming Newer Month-by-Month

If you’re attending SAS Forum UK in London this week (or Manchester later this month), you might not be expecting to use it as a means to find out what’s new in V9.4, after all V9.4 was released in summer 2013, so we can’t really call it “new” any…

What’s the most popular surname in your country?

My previous blog was about popular first names … now for a blog about popular surnames (ie, last/family names)! But before we get started, here’s a little pop-quiz – what country is my friend Mr. Foley’s surname from? I recently saw the following interesting map on dadaviz.com. It shows the most […]

The post What’s the most popular surname in your country? appeared first on The SAS Training Post.

Weird PROC FREQ trick

Default PROC FREQ output looks like this: Suppose you don’t want the two cumulative statistic columns above.  No problem.  Those can be suppressed with the NOCUM option on the TABLE statement, like this: proc freq data=sashelp.shoes; table product / nocum; run; Now your output looks like this, but you lose […]

The post Weird PROC FREQ trick appeared first on The SAS Training Post.

saslib: a simple Python tool to lookup SAS metadata

saslib is an HTML report generator to lookup the metadata (or the head information) like PROC CONTENTS in SAS.
  • It reads the sas7bdat files directly and quickly, and does not need SAS installed.
  • Emulate PROC CONTENTS by jQuery and DataTables.
  • Extract the meta data from all SAS7bdat files under the specified directory.
  • Support IE(>=10), firefox, chrome and any other modern browser.

Installation

pip install saslib
saslib requires sas7bdat and jinjia2.

Usage

The module is very simple to use. For example, the SAS data sets under the SASHELP library could be viewed —
from saslib import PROCcontents

sasdata = PROCcontents('c:/Program Files/SASHome/SASFoundation/9.3/core/sashelp')
sasdata.show()

The resulting HTML file from the codes above will be like here.

What’s the most popular baby name in your state?

A couple of years ago, I blogged about the most popular baby names in the US over the past 100 years. This time, I focus on the most recent year, and take it to the state level! But before we get started, here’s a picture of my friend Jennifer’s daughter, […]

The post What’s the most popular baby name in your state? appeared first on The SAS Training Post.

Looking for a SAS job? Join the 21-day SAS challenge

I recently taught a SAS training course where the students were very engaged. They had so many questions, I could have spent the next month writing helpful blog posts that came from that one class. However, I picked this one question that the class begged for me to share. The […]

The post Looking for a SAS job? Join the 21-day SAS challenge appeared first on The SAS Training Post.