BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
1 REPLY 1
deleted_user
Not applicable
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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 2316 views
  • 0 likes
  • 1 in conversation