46
To customize the command bar by using a command, see “COMMAND Command:
Windows” on page 330 . For more information about the Customize Tools Toolbars
tab, see “Setting General Toolbar Preferences” on page 78 .
Using the Command Line to Issue Commands
You can activate the command line so that each window contains a command line.
Commands that you enter in a window apply only to that window. For example, using
the INCLUDE command on the command line of the Enhanced Editor window applies
only to that window.
To activate the command line, use the COMMAND command without arguments. You
can also select Command Line from the Preferences dialog box View tab.
For more information, see “Setting Session Preferences ” on page 68 and
“COMMAND Command: Windows” on page 330 .
Sending Email Using SAS
Overview of Sending Email
You can use SAS to send electronic mail either interactively (using a dialog box) or
programmatically (using SAS statements in a DATA step or SCL). SAS supports three
types of electronic mail interfaces:
• MAPI (Mail API, such as Microsoft Exchange)
• VIM (Vendor Independent Mail)
• SMTP (Simple Mail Transfer Protocol).
You might need to install an email client that supports one of these protocols before you
can use SAS email support. Also, although you can use SAS to send messages, you must
use your email program to view or read messages.
When you send mail interactively, SAS automatically includes the contents of the active
window as an attachment to your email. Depending on the contents of the active
window, the attachment can be a text file (.TXT), a bitmap (.BMP), an HTML file
(.HTML), or an RTF file (.RTF).
SMTP is available only by using the FILENAME statement for email. If you specify
SMTP as the email system in the EMAILSYS system option and you are using an email
dialog box, the MAPI email system is used. For information about using SMTP, see SAS
Language Reference: Concepts as well as “FILENAME Statement, EMAIL (SMTP)
Access Method” in SAS Statements: Reference , the “EMAILHOST= System Option” in
SAS System Options: Reference , and the “EMAILPORT System Option” in SAS System
Options: Reference .
Initializing Email
To send email from within SAS, use the following system options that are appropriate
for your email system in the SAS configuration file or when you invoke your SAS
session. These email options can be set anytime in the configuration file, when invoking
SAS, or during the SAS session.
-EMAILSYS MAPI | VIM | SMTP
specifies which email interface to use. By default, SAS uses MAPI. The SMTP
interface is available only when you send email programmatically. SMTP is not
available when you use either your email program native dialog box or the SAS
email dialog box.
52
Chapter 2 • Interacting with SAS under Windows
VB.NET PDF- View PDF Online with VB.NET HTML5 PDF Viewer NET PDF file & pages edit, C#.NET PDF pages extract, copy, paste, C#.NET rotate PDF pages, C#.NET search text in PDF Support to zoom in and zoom out PDF page.
remove text watermark from pdf online; delete text from pdf online
48
Note: The directory that contains the email DLL file (for example, MAPI32.DLL or
VIM32.DLL) must be specified in your Windows PATH environment variable.
SAS uses the first email DLL that it finds for the interface that you specify.
-EMAILDLG NATIVE | SAS
specifies whether to use the native email interactive dialog box that is provided by
your email application or the email interface that is provided by SAS. SAS uses the
native dialog box by default.
-EMAILHOST SMTP server
specifies the domain name for the SMTP server that supports email access for your
site. This option is necessary only if you are using the SMTP email interface.
Multiple SMTP servers can be specified:EMAILHOST SMTP server|
(‘server1’ ‘server2’ <...’server-n’>)
For more information about the EMAILHOST option and more suboptions, see the
EMAILHOST option in the SAS System Options: Reference
-EMAILAUTHPROTOCOL authorization protocol
specifies the authorization protocol to use in SMTP email. The default for this option
is NONE. The only supported protocols are LOGIN and PLAIN.
-EMAILID VIM email login ID | MAPI profile | email address
specifies either your VIM email login ID, the MAPI profile that you use to access the
underlying email system, or a fully qualified email address if you are using SMTP. If
any of these values contain spaces, you must enclose them in double quotation
marks.
-EMAILPORT port number
specifies the port number to which the SMTP server is attached. This option is
necessary only if you are using the SMTP email interface. The default port is 25.
-EMAILPW “password”
specifies your email login password, where password is the login password for your
login name. If password contains spaces, you must enclose the password in double
quotation marks. Passwords can be encoded. You can create an encoded password
with PROC PWENCODE.
Using Your Email Software to Send Mail
The default value of the EMAILDLG system option is NATIVE, which enables you to
use your own email software when you send email interactively from within SAS. To
send email by using your own email software, do one of the following:
• Select File
ð
Send Mail.
• Type DLGSMAIL in the command bar.
Your email software provides the interface to send mail.
Using the SAS Send Mail Dialog Box
If the value of the EMAILDLG system option is set to SAS, you can send electronic
mail by using the Send Mail dialog box that is provided by SAS, as shown in the
display.
To send email system by using the Send Mail dialog box, select File
ð
Send Mail.
Working within Your SAS Session
53
32
Figure 2.3 Send Mail Dialog Box
The Send Mail dialog box contains the following fields:
To
the primary recipients of your email. You must specify one or more email addresses
that are valid for your mail system before you can send email. Separate multiple
recipients with a semicolon (;).
Cc
the email addresses of any users that you want to receive a copy of the mail that you
are sending. You can leave this field blank if you want. Separate multiple recipients
with a semicolon (;).
Bcc
specifies the recipients who receives a copy of the email. These addresses are not
visible to those individuals in the TO and CC options.
Subject
the subject of your message. You can leave this field blank.
Note
You can copy text from SAS application windows or other Windows applications
and paste it here (using the CTRL+C and CTRL+V accelerator key combinations). If
your note text exceeds the window space that is provided, you can scroll backward
and forward by using the arrow keys, or you can use the PgUp and PgDn keys.
Some email systems currently limit the note length to 32K (or 32,768 characters).
Text that you type in the Note area are automatically wrapped at the right side.
For large amounts of text, attach a text file as described below.
Attachments
icons and names of any files that you want to send with the message. You or the
recipient can open an attached file by double-clicking its icon, provided that its file
extension has a File Manager association with a Windows application (for example,
the .TXT extension might be associated with Notepad).
To open a file selection dialog box that you can use to select files to attach, click
Attach File.
54
Chapter 2 • Interacting with SAS under Windows
48
To remove an attachment, select the file's icon in the Attachments field and click
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 email message, the saved version of the file is sent with
the message.
To verify whether the addresses that you specified in the To and Cc fields are valid, click
Check Names. If one or more of the addresses is ambiguous (that is, the mail program
cannot locate them in the address books) SAS 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 who are outside your immediate local-area-network (LAN) by using gateways,
even though the addresses might not be resolved by using Check Names.
Whether an address is considered invalid or ambiguous depends on the email program
that you are using and on the configuration of your network. For example, suppose you
want to send email to a colleague on the Internet. Your LAN might have a gateway to the
Internet that enables you to 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 Internet gateway, the address is considered valid. However, when you click
Check Names, the address is considered ambiguous because the final destination
address cannot be resolved by using the local address book. You can still click Send to
send the message without an error.
Clicking Address invokes the address book facility for your email program, provided
that the facility is accessible.
Sending the Contents of a Window by Email
When you send mail from within SAS, SAS automatically attaches to the email the
contents of the active window. The type of file that SAS creates depends on the active
window:
Table 2.1 File Type for Email Messages (by Active Window)
File Type
Active Window
.txt
Log
Output
Enhanced Editor
Program Editor
.bmp
Explorer
Graphics
Results
.htm
Results Viewer window and the output type is
HTML
.rtf
Results Viewer window and the output type is
RTF
Working within Your SAS Session
55
45
Using the DATA Step or SCL to Send Email
By using the EMAIL access method, you can use the DATA step or SCL to send
electronic mail from within SAS. This method has several advantages:
• You can use the logic of the DATA step or SCL to subset email distribution based on
a large data set of email addresses.
• You can automatically send email upon completion of a SAS program that you
submitted for batch processing.
• You can direct output through email based on the results of processing.
• You can send email messages from within a SAS/AF FRAME application,
customizing the user interface.
In general, DATA step or SCL code that sends electronic mail has the following
components:
• a FILENAME statement that contains the EMAIL device-type keyword
• options that are specified in the FILENAME or FILE statement that indicate the
email recipients, subject, and any attached files
• PUT statements that contain the body of the message
• PUT statements that contain special email directives (of the form !EM_directive!)
that can override the email attributes (TO, CC, BCC, SUBJECT, ATTACH) or
perform actions (such as SEND, ABORT, and NEWMSG).
To send email by using the DATA step or SCL, you must be signed on to your email
program.
The FILENAME statement syntax to send email is
FILENAME fileref EMAIL 'address' <email-options>;
where
fileref
is a valid fileref.
EMAIL
is the device-type keyword that indicates that you want to use email.
'address'
is the valid destination email address that you want to send mail to. You must enclose
the address in quotation marks. Specifying an address as a FILENAME statement
argument is optional if you specify the TO= email option or the PUT statement !
EM_TO! directive, which overrides an address specification.
email-options
can be any of the following:
Note: Each email option can be specified only in a FILENAME statement that
overrides the corresponding SAS system option.
EMAILID= email login ID | MAPI profile | email address
specifies your email login ID, MAPI profile name, or your SMTP email address
that is used to access the underlying email system. If you specify MAPI in the
EMAILSYS system option, specify your profile name. If the value contains a
space, enclose the name in double quotation marks. This email option can be
specified in the FILENAME statement that overrides the SAS system option.
56
Chapter 2 • Interacting with SAS under Windows
51
EMAILPW=“password”
specifies your email login password, where password is the login password for
your login name. If password contains a space, enclose it in double quotation
marks. This email option can be specified in the FILENAME statement that
overrides the SAS system option.
EMAILSYS=MAPI | VIM | SMTP
SAS supports three types of email interfaces:
MAPI Mail API is the interface that is supported by Windows operating
environments, which is used by Microsoft Exchange. MAPI is the default.
VIM Vendor Independent Mail.
SMTP Simple Mail Transfer Protocol.
TO=to-address
specifies the primary recipients of the email. If an address contains more than
one word, you must enclose the address in double quotation marks. If you want
to specify more than one address, you must enclose the group of addresses in
parentheses and each address in double quotation marks. For example, valid TO
values are to="John Smith" to=("J. Callahan" "P. Sledge")
CC=cc-address
specifies the recipients who receives a copy of the email. If an address contains
more than one word, you must enclose the address in double quotation marks. If
you want to specify more than one address, you must enclose the group of
addresses in parentheses and each address in double quotation marks. For
example, valid CC values are cc="John Smith" cc=("J. Callahan"
"P. Sledge")
BCC=bcc-address
specifies the recipients who receive a copy of the email. These addresses are not
visible to those individuals in the TO and CC options. If an address contains
more than one word, you must enclose the address in double quotation marks. If
you want to specify more than one address, you must enclose the group of
addresses in parentheses and each address in double quotation marks. For
example, valid BCC values are bcc="John Smith" bcc=("J. Callahan"
"P. Sledge")
SUBJECT=subject
specifies the subject of the message. If the subject text is longer than one word
(that is, it contains at least one blank space), you must enclose the text in double
quotation marks. You must also use quotation marks if the subject contains any
special characters. For example, subject=Sales and subject="June
Report" are valid subjects.
ATTACH=filename.extATTACH=(filename.ext <LRECL=record-length>
<RECFM=record-format>)
filename.ext specifies the full path and filename of one or more files to attach to
the message.
LRECL=record-length specifies the record length (in bytes). Under Windows,
the default is 32767. The value of record-length can range from 1 to
1,073,741,823 ( 1 gigabyte).
RECFM=record-format controls the record format. The following values are
valid under Windows:
F indicates fixed format.
N indicates binary format and causes the file to be treated as a byte stream.
Working within Your SAS Session
57
50
P indicates print format.
V | D indicates variable format. This value is the default.
If you want to attach more than one file or if you want to specify a record length
and record format, you must enclose the group of filenames in parentheses and
each filename in double quotation marks. For example, valid values for file
attachments are attach=opinion.txt attach=("june2004.txt"
"july2004.txt") attach=("home.html" recfm=v lrecl=372);
If your email system is SMTP, see “FILENAME Statement, EMAIL (SMTP)
Access Method” in SAS Statements: Reference for additional ATTACH
arguments.
Options that you specify in a 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 email fileref as the output destination, use PUT statements to
define the body of the message. For an example of using email options in the FILE
statement, see Example Code 2.2 on page 59 .
You can also use PUT statements to specify email 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 that is associated
with the directive that it specifies. The following are the directives that change your
message attributes:
!EM_TO! addresses
replaces the current primary recipient addresses with addresses. If a single address
contains more than one word, you must enclose that address in quotation marks. If
you want to specify more than one address, you must enclose each address in
quotation marks and the group of addresses in parentheses.
!EM_CC! addresses
replaces the current copied recipient addresses with addresses. If you want to specify
more than one address, you must enclose each address in quotation marks and the
group of addresses in parentheses.
!EM_BCC! addresses
replaces the current copied recipient addresses with addresses. These recipients are
not visible to the !EM_TO! or !EM_CC! addresses. If you want to specify more than
one address, you must enclose each address in quotation marks and the group of
addresses in parentheses.
!EM_SUBJECT! 'subject'
replaces the current subject of the message with subject.
!EM_ATTACH! filename.ext
replaces the names of any attached files with filename.ext. If you want to specify
more than one file, you must enclose each filename in quotation marks and the group
of filenames in parentheses.
Here are the directives that perform actions:
!EM_SEND!
sends the message with the current attributes. By default, SAS sends a message when
the fileref is closed. The fileref closes when the next FILE statement is encountered
or the DATA step ends. If you use this directive, SAS sends the message when it
encounters the directive, and again at the end of the DATA step. This directive is
useful for writing DATA step programs that conditionally send messages or use a
loop to send multiple messages.
58
Chapter 2 • Interacting with SAS under Windows
49
!EM_ABORT!
abends the current message. You can use this directive to stop SAS from
automatically sending the message at the end of the DATA step. By default, SAS
sends a message for each FILE statement.
!EM_NEWMSG!
clears all attributes of the current message that were set by using PUT statement
directives.
Example of Sending Email from the DATA Step
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.
Example Code 2.1 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 email options in the FILE statement instead of the FILENAME
statement.
Example Code 2.2 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.
Example Code 2.3 Sending Customized Messages Using the DATA Step
filename reports email "Jim";
Working within Your SAS Session
59
54
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 email 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 email options in the FILENAME statement instead of in the
FILE statement. This method overrides 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.';
60
Chapter 2 • Interacting with SAS under Windows
Documents you may be interested
Documents you may be interested