|SAS Companion for the Microsoft Windows Environment|
The SAS System lets you send electronic mail either interactively (using a dialog box) or programmatically (using SAS statements in a DATA step or SCL). SAS supports these types of electronic mail interfaces: MAPI (such as Microsoft Exchange) and Vendor Independent Mail (VIM--such as Lotus cc:Mail and Lotus Notes).
To send e-mail from within SAS, select the File pull-down menu and then select Send.... Your electronic mail software provides the interface to send mail.
Note: You need an electronic mail program that supports
one of these protocols before you can take advantage of the SAS System's electronic
mail support. Also, although you can use the SAS System to send messages,
you must use your electronic mail program to view or read messages.
|Initializing Electronic Mail|
The electronic mail feature of the SAS System supports the following SAS system options in the SAS configuration file or when invoking your SAS session:
Note: The directory
that contains the e-mail DLL file (for example, MAPI32.DLL or VIM32.DLL) must
be specified in your Windows PATH environment variable. The SAS System will
use the first e-mail DLL that it finds for the interface you specify. Your
installed e-mail support must use 32-bit architecture.
For example, if your login ID is
J.B. Smith and
your password is
rosebud, your SAS invocation might look like:
c:\sas\sas.exe -emailsys vim -emailid "J.B. Smith" -emailpw rosebud
Note: If you don't specify the EMAILID and EMAILPW system
options at invocation (and you are not otherwise logged in to your e-mail
system already), the SAS System will prompt you for them when you initiate
You must have a 32-bit e-mail client program to initiate e-mail from the SAS System.
|Using the Send Mail Dialog Box to Send Electronic Mail|
The default value of the EMAILDLG system option is NATIVE, which lets you take advantage of your own e-mail software when sending e-mail from within SAS. If the value of the EMAILDLG system option is set to SAS, you can send electronic mail using a dialog box provided by the SAS System. If you are using the native e-mail interface provided by your e-mail system vendor, this discussion about the Send Mail dialog box does not apply to you. For more information about using that interface, see the documentation from your e-mail vendor.
You can access the Send Mail dialog box by selecting the Send... item from the File menu. Send Mail Dialog Box shows the Send Mail dialog box.
Send Mail Dialog Box
The following are descriptions of the fields in the Send Mail dialog box:
Some e-mail systems currently limit the note length to 32K (or 32,768 characters). Text that you enter in the Note: area will automatically wrap at the right side.
For large amounts of text, attach a text file as described below.
Use the [Attach File...] button to open a file selection dialog box that you can use to select files to attach. To remove an attachment, select the file's icon in the Attachments field and click on [Remove].
Note: The attached files are sent as
they exist on the
disk; that is, if you edit a file before attaching it to an e-mail message,
the saved version of the file is sent with the message.
To verify whether the addresses you specified in the To: and Cc: fields are valid, click on [Check Names]. If one or more of the addresses is ambiguous (that is, the mail program cannot locate them in the address books) the SAS System displays an error message and highlights the first ambiguous address.
Note that an ambiguous address is not necessarily invalid. It is possible to send mail to recipients outside of your immediate LAN (using gateways), whose addresses might not be resolved by using [Check Names].
Whether an address is considered invalid or ambiguous
depends on the e-mail program you are using and on the configuration of your
network. For example, suppose you want to send e-mail to a colleague on the
Internet. Your LAN might have a gateway to the Internet such that you can
address the mail to
JBrown@rhythm.com at Internet (where
at is the gateway
directive keyword and
Internet is the name of a gateway on your LAN). Because
your mail program uses the
at keyword to direct your message to the
the address is considered valid. However, when you click on [Check
Names], the address is considered ambiguous because the final destination
address cannot be resolved using the local address book. You can still click
on [Send] to send the message without an error.
Clicking on [Address...] invokes the address book facility for your e-mail program, provided the facility is accessible.
|Using the DATA Step or SCL to Send Electronic Mail|
Using the EMAIL access method, you can use the DATA step or SCL to send electronic mail from within the SAS System. This has several advantages:
In general, DATA step or SCL code that sends electronic mail has the following components:
To send e-mail using the DATA step or SCL, you must
be signed on to your e-mail program. For more information about how to use
your electronic mail program with the SAS System, see Sending Electronic Mail from within the SAS System.
|FILENAME fileref EMAIL 'address' <email-options>;|
Note: Each e-mail option can be specified only in a FILENAME statement
which overrides the corresponding SAS system option.
to=("J. Callahan" "P. Sledge")are valid TO values.
cc=("J. Callahan" "P. Sledge")are valid CC values.
subject="June Report"are valid subjects.
attach=("june94.txt" "july94.txt")are valid file attachments.
You can also specify the email-options in the FILE statement inside the DATA step. Options that you specify in the FILE statement override any corresponding options that you specified in the FILENAME statement.
In your DATA step, after using the FILE statement to define your e-mail fileref as the output destination, use PUT statements to define the body of the message.
You can also use PUT statements to specify e-mail directives that change the attributes of your electronic message or perform actions with it. You can specify only one directive in each PUT statement; each PUT statement can contain only the text associated with the directive it specifies. Here are the directives that change your message attributes:
Here are the directives that perform actions:
Suppose you want to share a copy of your SAS configuration file
with your coworker Jim, whose user ID is
JBrown. Sending a File with the Data Step shows how to send the file with the DATA
Sending a File with the Data Step
filename mymail email "JBrown" subject="My SASV8.CFG file" attach="c:\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;
Attaching a File and Specifying Options in the FILE Statement 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. Sending Customized Messages Using the Data Step shows such a DATA step.
Sending Customized Messages Using the Data StepThe resulting e-mail message, and its attachments, are dependent on the department to which the recipient belongs.
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;
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.
Overriding SAS System Options shows how to send a message and to attach a file to multiple recipients, and it specifies the e-mail options in the FILENAME statement instead of the FILE statement. This has the effect of overriding the values for the SAS system options EMAILID, EMAILPW, and EMAILSYS.
Overriding SAS System Options
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;
The following example is the SCL code behind a FRAME entry designed for e-mail. The FRAME entry might look similar to the one shown in An Example E-Mail FRAME Entry.
An Example E-Mail FRAME Entry
The FRAME entry has objects that let the user enter information:
|MAILTO||the user ID to send mail to.|
|COPYTO||the user ID to copy (CC) the mail to.|
|ATTACH||the name of a file to attach.|
|SUBJECT||the subject of the mail.|
|LINE1||the text of the message.|
Invoking SCL Code from a FRAME Entry
shows the FRAME entry which also contains a pushbutton called SEND that invokes
this SCL code (marked by the
Invoking SCL Code from a FRAME Entry
send: /* set up a fileref */ rc = filename('mailit','userid','email'); /* if the fileref was successfully set up, open the file to write to */ if rc = 0 then do; fid = fopen('mailit','o'); if fid > 0 then do; /* fput statements are used to implement writing the mail and the components such as subject, who to mail to, etc. */ fputrc1= fput(fid,line1); rc = fwrite(fid); fputrc2= fput(fid,'!EM_TO! '||mailto); rc = fwrite(fid); fputrc3= fput(fid,'!EM_CC! '||copyto); rc = fwrite(fid); fputrc4= fput(fid,'!EM_ATTACH! '||attach); rc = fwrite(fid); fputrc5= fput(fid,'!EM_SUBJECT! '||subject); rc = fwrite(fid); closerc= fclose(fid); end; end; return; cancel: call execcmd('end'); return;
Top of Page
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.