Your SAS programs, embedded in web apps and elsewhere

Sending email via UNIX SAS

Posts: 0

Sending email via UNIX SAS

I am needing to find out how to send email via unix SAS. PC SAS is so easy, but it seems much harder in the UNIX SAS environment.

Any ideas or code examples???

I was give the example below but I don't have a firm grasp of what is going on in this program.

Macro: emailMsg
Parms: msgSubject - subject line of the email.
msg - body of the email msg.
type - TEXT, FILE, or PIPE. TEXT the body of the email msg
can be handled as a text string. FILE the body of the
email message is in a file that needs to be
concatenated to the email message. PIPE the body of
the email message will come from a UNIX command that
needs to be executed and the output redirected to the
body of the email.

This macro uses the sendmail command to email a message from within
a SAS program. The message body can be a text string, the contents
of a file or the output of a UNIX command. The macro expects to
find a file named email.header in the working directory. This file
contains the From: and To: portions of the email in the format:

From: "YourName"

The "YourName" portion of the email.header will be displayed as who
the email is coming from and does need to be in quotes. The To: portion
of the email can contain one or more comma separated email addresses.
%macro emailMsg(msgSubject, msg, type);

%local quote;
%let quote = %str(%');

%if ( %scan(&msg,1,%str( )) eq ) %then %do;

%sysexec echo &quote.Subject:&msgSubject.\n\n&quote |
cat email.header - |
sendmail -f -t;
%else %if ( %scan(&type,1,%str( )) eq ) or
( %scan(&type,1,%str( )) eq TEXT) %then %do;

%sysexec echo &quote.Subject:&msgSubject.\n\n&quote&quote.&msg.&quote |
cat email.header - |
sendmail -f -t;
%else %if ( %scan(&type,1,%str( )) eq FILE ) %then %do;

%sysexec echo &quote.Subject:&msgSubject.\n\n&quote&quote.&msg.&quote |
cat email.header &msg - |
sendmail -f -t;
%else %if ( %scan(&type,1,%str( )) eq PIPE ) %then %do;

%sysexec %str(&msg > .temp; )
echo &quote.Subject:&msgSubject.\n\n&quote&quote.Program:&msg.&quote |
cat email.header - .temp |
sendmail -f -t;
%mend emailMsg;
Message was edited by: darrenst at May 24, 2006 3:40 PM
Posts: 0

Re: Sending email via UNIX SAS

It should be a lot more straightforward than the example you detail here. Just try using the FILENAME statement with the EMAIL keyword:

filename mymail email ""
subject="My SAS Configuration File"

data _null_;
file mymail;
put 'Jim,';
put 'This is my SAS configuration file.';
put 'I think you might like the';
put 'new options I added.';

I copied this from the online docs where you can find all the various options. We use this method on UNIX and it works perfectly.
Ask a Question
Discussion stats
  • 1 reply
  • 1 in conversation