Suppose that you want to share a copy
of your config.sas file with your coworker Jim, whose user ID is JBrown.
If your e-mail program handles alias names and attachments, you could
send it by submitting the following DATA step:
filename mymail email 'JBrown'
subject='My CONFIG.SAS file'
attach='config.sas';
data _null_;
file mymail;
put 'Jim,';
put 'This is my CONFIG.SAS file.';
put 'I think you might like the
new options I added.';
run;
The following example
sends a message and two attached files to multiple recipients. It
specifies the e-mail options in the FILE statement instead of the
FILENAME statement:
filename outbox email 'ron@acme.com';
data _null_;
file outbox
/* Overrides value in filename statement */
to=('ron@acme.com' 'lisa@acme.com')
cc=('margaret@yourcomp.com'
'lenny@laverne.abc.com')
subject='My SAS output'
attach=('results.out' 'code.sas')
;
put 'Folks,';
put 'Attached is my output from the
SAS program I ran last night.';
put 'It worked great!';
run;
You can use conditional
logic in the DATA step to send multiple messages and control which
recipients get which message. For example, suppose you want to send
customized reports to members of two different departments. If your
e-mail program handles alias names and attachments, your DATA step
might look like the following:
filename reports email 'Jim';
data _null_;
file reports;
infile cards eof=lastobs;
length name dept $ 21;
input name dept;
/* Assign the TO attribute */
put '!EM_TO!' name;
/* Assign the SUBJECT attribute */
put '!EM_SUBJECT! Report for ' dept;
put name ',';
put 'Here is the latest report for ' dept '.';
/* ATTACH the appropriate report */
if dept='marketing' then
put '!EM_ATTACH! mktrept.txt';
else
put '!EM_ATTACH! devrept.txt';
/* Send the message */
put '!EM_SEND!';
/* Clear the message attributes */
put '!EM_NEWMSG!';
return;
/* Abort the message before the */
/* RUN statement causes it to */
/* be sent again. */
lastobs: put '!EM_ABORT!';
datalines;
Susan marketing
Jim marketing
Rita development
Herb development
;
run;
The resulting e-mail
message and its attachments are dependent on the department to which
the recipient belongs.
Note: You must use the !EM_NEWMSG!
directive to clear the message attributes between recipients. The
!EM_ABORT! directive prevents the message from being automatically
sent at the end of the DATA step.