Your SAS programs, embedded in web apps and elsewhere

Sending email via UNIX SAS

Reply
N/A
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"
To: jane.doe@company.com, john.doe@company.com

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 va2pwap010@company.com -t;
%end;
%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 va2pwap010@company.com -t;
%end;
%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 va2pwap010@company.com -t;
%end;
%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 va2pwap010@company.com -t;
%end;
%mend emailMsg;
Message was edited by: darrenst at May 24, 2006 3:40 PM
N/A
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 "JBrown@site.com"
subject="My SAS Configuration File"
attach="/u/sas/sasv8.cfg";

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.';
run;

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
  • 403 views
  • 0 likes
  • 1 in conversation