Tag: Advanced SAS

SAS Online training Youtube Channel

I have liked this set of you tube channel for SAS Online trainings…quite resourceful for beginners…

https://www.youtube.com/channel/UCtjfX85t_HG9ojSunObROIA

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

Creating a search engine in SAS

Its the age of the search engine! I remember people “yahoo”ing during the late 90’s and “Google”ing till the late 2k’s and now “Bing”ing.I just wondered.. Why not SAS? So I started off by doing some reading on the yahoo search engine API’s. They have n…

Making SAS Interactive (Part 2): Using %window and %display

Its the world of GUI. And you are left nowhere if you don’t provide the users, the luxury (or rather fulfill the basic needs) of giving a Graphical User Interface. This holds good even for SAS. SAS came up with the tool called SAS/AF and SAS EG which p…

Reading a table from a website into a SAS dataset

Many a times we may want to read a table from the webpages into our datasets. This may be a requirement especially when I would want to analyse the stock market shares and their corresponding trends over the past. This can be done in many ways dep…

SAS Macro to put SAS data into Multiple Excel Work sheets

I believe most of us have encountered this situation…
I have a sas dataset with more than 70k records…How can I provide this information in an Excel file to the business user….

If one is using previous versions of MS Excel ie. < Excel 2007 th…

Indexing in SAS.. In a baby’s language

A question at the KBC (Indianized version of Who wants to be a Millionire)If your answer happens to be anything other than C then this might not be a relevant post for you :-)There have been innumerable number of posts on indexing in SAS. One such bril…