Suppose you want to share a copy of your SAS configuration file
with your coworker Jim, whose user ID is
JBrown
. The following example code shows how to send the file with the
DATA step.
Sending a File with the DATA Step
filename mymail email "JBrown"
subject="My SASV9.CFG file"
attach="c:\sas\sasV9.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;
The following example
code sends a message and attaches a file to multiple recipients, and
specifies the e-mail options in the FILE statement instead of the
FILENAME statement.
Attaching a File and Specifying Options in the FILE Statement
filename outbox email "Ron B";
data _null_;
file outbox
/* Overrides value in */
/* filename statement */
to=("Ron B" "Lisa D")
cc=("Margaret Z" "Lenny P")
subject="My SAS output"
attach="c:\sas\results.out"
;
put 'Folks,';
put 'Attached is my output from the SAS';
put '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. The following
example code shows such a DATA step.
Sending Customized Messages Using the DATA Step
filename reports email "Jim";
data _null_;
file reports;
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 '.';
if dept='marketing' then
put '!EM_ATTACH! c:\mktrept.txt';
else /* ATTACH the appropriate report */
put '!EM_ATTACH! c:\devrept.txt';
/* Send the message. */
put '!EM_SEND!';
/* Clear the message attributes.*/
put '!EM_NEWMSG!';
/* Abort the message before the */
/* RUN statement causes it to */
/* be sent again. */
put '!EM_ABORT!';
cards;
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.
The following example
code shows how to send a message and attach a file to multiple recipients.
It specifies the e-mail options in the FILENAME statement instead
of in the FILE statement. This method will override the values for
the SAS system options EMAILID, EMAILPW, and EMAILSYS.
filename outbox email "Ron B" emailsys=VIM
emailpw="mypassword" emailid="myuserid";
data _null_;
file outbox
/* Overrides value in */
/* filename statement */
to=("Ron B" "Lisa D")
cc=("Margaret Z" "Lenny P")
subject="My SAS output"
attach="c:\sas\results.out"
;
put 'Folks,';
put 'Attached is my output from the SAS';
put 'program I ran last night.';
put 'It worked great!';
run;