Chapter Contents |
Previous |
Next |
SAS Companion for the CMS Environment |
SAS e-mail is implemented in the following language elements:
Using the Mail System Interface and the EMAILSYS= System Option |
SAS sends all e-mail through an external CMS pipeline stage that is written as a REXX exec. The name of the exec is SASMAIL REXX, and it is stored on the SAS system disk.
Note: The SASMAIL REXX exec may need to be customized with site-specific
information that is pertinent to your mail system. Comments at the beginning
of the exec guide you through the customizations. Work with your system administrator
and local SAS Support Consultant as needed.
You can use your own CMS pipeline stage instead of SASMAIL by specifying the name of your exec as the value of the EMAILSYS= system option. You can specify a value for EMAILSYS= in your SAS configuration file, in your SAS invocation command, or during your SAS session by using the OPTIONS statement or OPTIONS window. The syntax of the OPTIONS statement is as follows:
EMAILSYS='stage-specification' |
FILENAME Statement Syntax for Electronic Mail |
To send electronic mail from within a SAS session, issue a FILENAME statement of the following form:
FILENAME fileref EMAIL 'address' <e-mail-options>; |
to='joe@hisplace.org'To specify more than one address, enclose the group of addresses in parentheses and each address in single or double quotes, as follows:
to=('joe@hisplace.org' 'jane@herplace.org')To specify the recipient's name along with the address, enclose the address in angle brackets, as follows:
to="Joseph Smith <joe@hisplace.org>"A recipient can also be specified as a nickname to be resolved from your NAMES file.
Specifying the TO= option overrides the address argument.
cc='joe@hisplace.org'To specify more than one address, enclose the group of addresses in parentheses and each address in single or double quotes, as follows:
cc=('joe@hisplace.org' 'jane@herplace.org')To specify the recipient's name along with the address, enclose the address in angle brackets, as follows:
cc="Joseph Smith <joe@hisplace.org>"A recipient can also be specified as a nickname to be resolved from your NAMES file.
subject=Sales
subject='June Report'Any subject not enclosed in quotes is converted to uppercase.
attach='opinion txt'The filemode is `*' by default. To attach more than one file, enclose the group of file specifications in parentheses, as follows:
attach=('june98 txt .reports.june' 'july98 txt .reports.july')
type='text/plain' type='text/html' type='image/gif'
The TYPE value must be enclosed in quotes.
emailid='Joseph Smith <joe@hisplace.org>'
You can also specify the e-mail-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.
PUT Statement Syntax for E-Mail |
You can also use PUT statements to specify e-mail directives that change the attributes of your electronic message or perform actions with it. 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 directives that change the attributes of your message are as follows:
PUT "!EM_TO!" "joe@hisplace.org";or:
user="joe@hisplace.org"; put '!EM_TO!' user;
To specify more than one address, enclose the list of addresses in parentheses and enclose each address in single or double quotes, as follows:
PUT "EM_TO!" '("joe@hisplace.org" "jane@herplace.org")';or:
list='("joe@hisplace.org" "jane@herplace.org")'; put "!EM_TO!" list;
If you want to specify a recipient's name along with the e-mail address, include the address in angle brackets, as follows:
user='Joseph Smith <joe@hisplace.org>' PUT "EM_TO!" user;
A recipient can also be specified as a nickname that will be resolved from your NAMES file.
PUT "!EM_CC!" "joe@hisplace.org";or:
user="joe@hisplace.org"; put '!EM_CC!' user;
To specify more than one current copied recipient, enclose a list of addresses in parentheses and enclose each address in single or double quotes, as follows:
PUT "!EM_CC!" '("joe@hisplace.org" "jane@herplace.org")';or:
list='("joe@hisplace.org" "jane@herplace.org")'; put '!EM_CC!' list;
If you want to specify a recipient's name along with the address, enclose the address in angle brackets, as follows:
ccuser='Joseph Smith <joe@hisplace.org>'; PUT "!EM_CC!" ccuser;
A recipient can also be specified as a nickname that will be resolved from your NAMES file.
PUT '!EM_ATTACH!' 'opinion txt';
To attach more than one file, enclose each file specification in single or double quotes and enclose the list of file specifications in parentheses, as follows:
mycfg='sasv8 config *'; syscfg='sasv8sys config *'; PUT '!EM_ATTACH!' '("'mycfg'"' '"'syscffg'")';
The directives that perform actions are as follows:
Using the DATA Step, Procedures, or SCL Code to Send E-Mail |
In general, a DATA step, procedure, or SCL code that sends e-mail has the following components:
filename mymail email 'JBrown' subject='My SASV8 CONFIG file' attach='sasv8 config'; data _null_; file mymail; put 'Jim,'; put 'This is my SASV8 CONFIG 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 in the FILENAME statement:
filename outbox email 'ron@acme.com'; data _null_; file outbox to=('ron@acme.com' 'lisa@acme.com') /* Overrides value in */ /* filename statement */ cc=('margaret@yourcomp.com' 'steve@abc.com') subject='My SAS output' attach=('results listing' '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 to control which recipients get which message. For example, suppose that you want to send customized reports to members of two different departments. 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.
Procedures that write to filerefs can be used to send e-mail. The following example shows how to use the Output Delivery System (ODS) to send HTML output in e-mail:
filename outbox email to=susan type='text/html' subject='Temperature conversions' ; data temperatures do centigrade = -40 to 100 by 10; fahrenheit = centigrade*9/5+32; output; end; run; ods html body=outbox /* Mail it! */ rs=none; title 'Centigrade to Fahrenheit Conversion Table'; proc print; id centigrade; var fahrenheit; run; ods html close;
The following example shows how to create and send a GIF image in e-mail.
filename gsasfile email to=Jim type='image/gif' subject="SAS/GRAPH output" ; goptions dev=gif gsfname=gsasfile; proc gtestit pic=1; run;
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 |
The frame entry also contains a pushbutton called SEND
that causes this SCL code (marked by the
send:
label) to execute.
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 write the mail and the components, such as subject, address, 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;
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.