Teo Gamishev, Office of Research and Statistics, Columbia, SC
Download the PDF version from here
ABSTRACT
The first step in any data management process is transferring the data from the customer. There are many ways to do that and the most common one is to use proper FTP(File Transfer Protocol) software to navigate to the customer’s site and get the data. While this process is a fun in the beginning of your relationship with the customer, it may become just another boring step in your data management process. There is a way to reduce that step to a single click of the mouse. This article will show you how to use SAS to transfer data, located on a different type of servers.
INTRODUCTION
If you are dealing with multiple projects, requiring downloading data from the customer and uploading back reports on a regular basis, you definitely are looking for ways to automate that step and make it less time consuming for you. Here you’ll find several examples of how this could be done. Hopefully, they will work for you or inspire you to do your research and find a proper solution.
PROBLEMS
Different projects are using different servers, which demands different FTP applications to access their data. Accessing different folders and transferring the data into proper folders may become a hustle and creates an environment for errors and mishaps.
SOLUTIONS
There is a very simple way to eliminate all these activities and reduce them into a single click of the mouse: Delegate the entire data transfer to SAS. A SAS program can do the access, login, folder navigation and copying the data in the proper folder on your site.
The following 3 examples will give you a hint on how that could be done:
EXAMPLE #1: Accessing DASD area on a Mainframe
The data in the DASD area on the Mainframe is normally accessed via Hummingbird FTP. Here is one way to access the data trough SAS, without SAS ACCESS:
*** 1. Creating a batch file;
data _null_;
file 'C:\Data\Downloads\getDATA.bat' * the batch file;
noprint notitles;
put "ftp -s:%0";
put "goto END";
put "open 144.4.40.44";
put "&tsoID";
put "&tsoPW";
put "CD 'MY.DATA'";
put "LCD C:\Data\Downloads\MyData";
put "GET FILE138 EMPR";
put "GET FILE150 T1F1";
put "GET FILE152 T1F2";
put "GET FILE153 T1F3";
put "GET FILE157 T1F4";
put "bye";
put ":END";
run;
*** 2. Running the batch file to FTP the new data from the Mainframe;
options xwait xsync; * synchronizing the downloading process and SAS;
x " C:\Data\Downloads\getDATA.bat ";
*MONITOR THE DOWNLOADING THROUGH THE DOS PROMPT WINDOW POPPING UP *;
*** 3. Deleting the batch file;
Filename delit PIPE "del C:\Data\Downloads\getDATA.bat";
Data _null_; Infile delit; Run;
EXPLANATION NOTES
A batch file is created in the Step #1. The user ID and the password are passed to the server as macro variables. Those macro variables should be created in your AUTOEXEC.sas file or the access to the SAS program should be limited to you, only. The CD(Change Directory) command is navigating to the data folder on the Mainframe. The LCD (Local Change Directory) command is pointing to your destination folder.
"GET FILE150 T1F1" copies FILE150 from the Mainframe, renames it to T1F1 and saves it into the local data folder.
Once the batch file is created, SAS can activate the file using X command (Step #2). The option XWAIT forces SAS to wait for you to type EXIT on the COMMAND window, before moving to the next step. I like to watch the COMMAND window, which pops up after the X command. When sure that everything is executed properly, I will type EXIT on the Command window and then the SAS program will move to the next step. Automation is good, however quality control needs to be applied on each step to make sure that nothing is messed up. Here comes the role of the human eye to verify that and then move forward.
The next option XSYNC causes the operating environment command to run synchronously with your SAS session. That is, control is not returned to the SAS System until the command has completed.
In step #3 the batch file is deleted using the Filename PIPE statement. Considering the fact that the batch file contains a sensitive data like your login ID and Password, this step is mandatory one.
EXAMPLE #2: Accesing a Secure FTP server via psftp
*** 1. Creating a text file with all commands;
data _null_;
file "C:\Data\UploadReports.txt"
noprint notitles;
* uploading reports and data for Client1;
put "cd /chroot/home/client1/Reports";
put "del *.*";
put "lcd C:\Reports\StatPack";
put "mput *.*";
put "cd /chroot/home/client1/Data";
put "del *.zip";
put "lcd C:\Zipfiles";
put "mput *.zip";
* uploading reports and data for client2;
put "cd /chroot/client2/Reports";
put "del *.*";
put "lcd C:\Reports\StatPack";
put "mput *.*";
run;
*** 2. Executing the commands above;
options xwait xsync; * synchronizing the downloading process and SAS steps;
x "C:\sshtools\psftp.exe -P 2251 -b C:\Data\ UploadReports.txt
-l &sftpID -pw &sftpPW courier.state.gov";
*** 3. Deleting the text file;
Filename delit PIPE "del C:\Data\Uploads\UploadReports.txt";
Data _null_; Infile delit; Run;
EXPLANATION NOTES:
The steps here are very similar to the steps in the Example#1. The Step 1 we are creating a text file, containing all commands the software need to execute. In this case we are uploading the final reports to a secure server. In case of several clients receiving different set of reports, that example could be very helpful.
In Step 2, SAS is triggering the PSFTP.exe file via X command. The PSFTP software should be installed in advance. It is free application for secure file transfer, available on Internet. The X command contains the path to the PSFTP.exe and the name of the server to connect to. The following options are needed to complete the task:
-P: specify a port number
-l: specify the user name to log in – in this case the log in is in a macro variable
-pw: specify a password – stored in a macro variable, also
-b: display batch commands as they are run – in this case they are stored in the text file, created in Step 1
The macro variables, containing the user ID and the password can be created within the AUTOEXEC.sas to avoid hard coding them in the program.
Step 3 deletes the text file with the batch commands to clear the space.
EXAMPLE #3: Accessing WS server:
*** transferring the data;
options xwait xsync; * synchronizing downloading and SAS steps;
X "c:\progra~1\coreftp\coreftp.exe -site CAPS -d /*.txt -p D:\data\capss";
EXPLANATION NOTES:
This is the shortest example of how to access a WS server, using Core FTP Light free client software for windows. In this case Core FTP has to be installed and a session, containing all prerequisites to connect to the server (user ID, password, port number), has to be established and saved using a particular name. In our example that session is named CAPS. The X command is triggering the coreftp.exe and the following options are in use:
-site: site session/profile name as stored in the Core FTP - CAPS
-d: remote directory to download files from – in this case we are downloading all test files - /*.txt
-p: destination directory - D:\data\capss
If you need to upload data or reports, then use the following example:
*** transferring the data;
options xwait xsync; * synchronizing downloading and SAS steps;
X "c:\progra~1\coreftp\coreftp.exe -site mysite -u /upload/data.txt -p /remote/store";
Other available options are:
-ZIP: zipping the file(s)
-AUTONAME: naming the files after zipping
-output and -log parameter are for information about transfers
-s: silent mode – the application window doesn’t open
-o: overwrite if file exists
-oa: overwrite *all* if transfering a folder or directory of files.
-on: overwrite files that are newer than existing files.
-og: overwrite destination file if source file size is greater.
-ol: overwrite destination file if source file size is less (smaller).
-os: skip file if exists
-r: resume if file exists
-ra: resume *all* files that exist.
Here is an example of zipping the files before uploading them:
X "c:\progra~1\coreftp\coreftp.exe -O -ZIP -AUTONAME -u c:\IBM -site mysite -p /public_html/store/ -output c:\temp\output.log -log d:\temp\log.log –s";
-output and -log parameter are for information about transfers. They are optional but listed for informational purposes.
AUTOMATING THE ENTIRE PROCESS is a preferred way to go when dealing with repetitive tasks. In this case the entire downloading and uploading programs can be saved and called from within another DRIVING program. Here is an example of the triggering code in the DRIVING program:
EXAMPLE#4: Downloading Driving program:
***************************************************************************;
*** STEP ONE ***;
*** DOWNLOADING MONTHLY EXTRACTS ***;
***************************************************************************;
**** MAKE SURE THAT THE ID AND PASSWORD ARE SUBMITTED FIRST ***;
%include "C:\Programs\getDATA.sas";
*** MONITOR THE DOWNLOADING THROUGH THE DOS PROMPT WINDOW POPPING UP ***;
*** CHECK THE FILE SIZE ***;
EXPLANATION NOTES:
The first step in each data project is to get the data from the customer. Once the SAS program dealing with that process is ready and tested for proper work, it can be saved and called from within another DRIVING SAS program. All the programmer needs to do is to select and submit the part of the code, triggering the data downloading process. Now the entire focus is on the quality and all the tedious typing and coding is removed. The best part is that the room for coding errors is practically zero.
EXAMPLE#5: Uploading Driving program:
***************************************************************************;
*** STEP FIVE ***;
*** UPLOADING THE REPORTS AND THE SAS TABLES INTO SFTP Server ***;
***************************************************************************;
%include "C:\Programs\UploadingReports.sas";
*** CHECK ALL NEW FILES ARE UPLOADED IN THEIR RELEVANT FOLDERS ***;
EXPLANATION NOTES:
Once we are done with the data manipulations and reports are ready to upload to different customers, the whole task can be triggered again from within the DRIVING program. Select and submit that part of the code invoking the uploading program, dealing with reports and data distribution and focus on quality control. No mishaps, no errors, no boring job to do. Enjoy the power of automation and focus on quality control.
CONCLUSION
This paper offers one of the many possible solutions on how to remove the repetitive downloading and uploading tasks by using the power of SAS. The above examples are giving hints on how to deal with different servers. In addition examples are given on how the whole process can be automated. It can be very practical and time saving to implement those examples in the daily routine.
SAS Global Forum 2007 Coders’ Corner
REFFERENCES
SAS Institute Inc. 2002-2008 “SAS OnlineDoc® 9.1.3” Available at: http://support.sas.com/onlinedoc/913
Gary Sargent 2006 “Core FTP LE Client Instructions”
Available at:http://www.ic.nhs.uk/webfiles/Services/Datasets/MHMDS/MHBScoreftp.doc
Simon Tatham 2001 “PuTTY Manual”
Available at: http://the.earth.li/~sgtatham/putty/0.52/htmldoc/Chapter6.html
ACKNOWLEDGMENTS
Special heartfelt thanks to Jim Moore, IT Technician at BCB-ORS for his helpful hints and guidance.
CONTACT INFORMATION
Your comments and questions are valued and encouraged. Contact the author:
Teo Gamishev
Office of Research and Statistics
1919 Blanding Street
Columbia, SC 29201
gamishev@hotmail.com
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS
Institute Inc. in the USA and other countries. ® indicates USA registration.
Other brand and product names are trademarks of their respective companies.
Wednesday, March 31, 2010
How to Manage Emails from SAS
Teo Gamishev, Office of Research and Statistics, Columbia, SC
Download the PDF version from here
ABSTRACT
Setting up part of your email workload on autopilot from within SAS can eliminate the need of redundant work and significantly increase your job efficiency when dealing with repetitive tasks. SAS has built in emails generating engine, which when tuned properly, works very well with every email provider. Here you’ll find an example of fully automated process of emailing reports to several customers, using SAS.
INTRODUCTION
If you are emailing reports to your customers on a regular basis, then you definitely can benefit from the material laid out in this article. At least, it will motivate you to start testing, tweaking and having fun reading your first, successfully delivered emails. At the end you may end up using and enjoying this fully automated emailing system.
PROBLEMS
Here is a list of the problems covered on the following pages:
How to tune up your program to successfully deliver emails to a list of customers and supervisors;
How to generate the emails;
How to automate the entire process;
SOLUTIONS
TUNING UP SAS EMAIL ENGINE is not a rocket science, however I found it was not easy to locate the proper instructions on that. So, here is how it can be done:
EXAMPLE:
OPTIONS EMAILAUTHPROTOCOL=NONE
EMAILHOST=”mail.my.state”
EMAILID=”My.Name@MyCompany.com”
EMAILSYS=SMTP;
Email providers should be accessible from within the company without necessity of logging in and using a password. If that is not possible, then you should change the
EMAILAUTHPROTOCOL=LOGIN
After failing many times when trying to connect to my email provider, using the login protocol, our IT person gave me the hint of using a different host name to connect to it, without using user ID and password. You need to do your research and type the right hostname under EMAILHOST option, in order to assure smooth operation.
The EMAILID option contains your email address. If you just type a name or invalid email that may cause the email providers to filter out your messages or force them into the junk box. On another side, our email provider recognizes the fact that the sender and one of the recipients under the CC list are the same and refuses to deliver a copy of the emails to my Inbox. Your email provider may not be so smart, but you can always be creative here and use another email of yours to email a copy to yourself, if so needed.
The EMAILSYS option should be adjusted to SMTP(Simple Mail Transfer Protocol). The other possibilities are: MAPI(Messaging Application Program Interface) or VIM(Vendor Independent Messaging) . Those two may require login and password to access the server.
Here is how you tune your program for that:
OPTIONS EMAILAUTHPROTOCOL=LOGIN
EMAILHOST=”ciomail.my.state”
EMAILID="MyLogin" /* your email login */
EMAILPW="MyPass" /* your email password */
EMAILSYS=MAPI;
The fact that I have to type and leave sensitive information in my program doesn’t make me feel good about that. My advice is to move that entire OPTIONS statement into your AUTOEXEC.SAS file. However, make sure that your profile is in use every time when open a new SAS session. Not all servers, where SAS has been installed, are set up that way. Most of them will read the information in your AUTOEXEC.SAS during the first session and will skip it for the next sessions. Read the message into your log right after opening the second session. If you see the following message posted there, you will know that the OPTIONS statement and all other statements in the AUTOEXEC.SAS has not been activated. Copy and submit them from within your session, first.
NOTE: Unable to open SASUSER.PROFILE. WORK.PROFILE will be opened instead.
NOTE: All profile changes will be lost at the end of the session.
Once all of the above tuning is done, it is a good idea to check the options by submitting the following code:
proc options group=email; run;
GENERATING THE EMAILS from within SAS is an easy task to do. Let’s take a look at the example below:
EXAMPLE:
FILENAME outbox EMAIL
TO=”Perfect.Client@agency.gov”
CC=”Smart.Manager@company.com”
SUBJECT="Monthly Reports Uploaded"
;
data _null_;
file outbox;
put "Good Morning, ";
put " ";
put "The monthly Reports are uploaded";
put "into your Secure FTP folder.";
put " ";
put "Let me know if you have any questions. ";
put "Thank you and have a nice day";
put " ";
put "My Name";
put "ph:898-9999";
put "My.Email@company.com";
run;
There are two ways to address the recipient of the email:
By using the TO= option
FILENAME outbox EMAIL
TO=”Perfect.Client@agency.gov”
or
TO="My Customer"
Or without using the TO= option and listing the recipient as an argument right after the EMAIL device type in the FILENAME statement:
FILENAME outbox EMAIL ”Perfect.Client@agency.gov”
Listing multiple recipients can be done by using the TO= option:
FILENAME outbox EMAIL
TO= (”Perfect.Client@agency.gov”
”Dream.Client@agency.gov”
”Polite.Client@agency.gov”)
In a similar way, multiple recipients can be listed under CC=:
CC= (”Best.Supervisor@company.gov”
”Smart.Manager@company.gov”
”Awesome.Boss@company.gov”)
Other useful options are:
FROM= /* your email */
BCC= /* recipient(s) that you want to receive a blind copy */
REPLYTO= /* who will receive replies */
SUBJECT= /* subject of the message */
ATTACH= /* physical name of the file(s) to be attached */
Make sure to enclose the SUBJECT= into double quotes, If the subject contains special characters or more than one word (that is, it contains at least one blank space).
EXAMPLE:
SUBJECT=Sales
or
SUBJECT="June Sales Report"
Note: If you do not enclose a one-word subject in quotation marks, it is converted to uppercase.
One or more files can be attached to the email:
EXAMPLE:
ATTACH=u/myfiles/report.txt"
or
ATTACH=('D:\Reports\June2001.txt' 'C:\Reports\July2001.txt')
or
ATTACH="user.misc.pds(member)"
AUTOMATING THE ENTIRE PROCESS can give you the flexibility to modify and the power to send the email(s) with a single click. All the variables can be controlled within a one program (driving program) and the execution of the emailing can be done from another program (work program). Below is an example on how that can be achieved:
1. The following code is located in the DRIVING program:
**********************************************************************;
*** STEP X ***;
*** EMAILING TO MY CUSTOMERS ***;
**********************************************************************;
*** PLEASE CHANGE THE DATA BELOW, AS NECESSARY;
*** reduces the hustle, when the programs are moved to a new server***;
%let thepath=D:\Projects\FS;
%let myemail=My.Name@MyCompany.com;
%let myname=My Name;
%let myphone=(803)888-7777;
%let clients=”Perfect.Client@agency.gov”
”Dream.Client@agency.gov”
”Polite.Client@agency.gov”;
%let CCline=”Best.Supervisor@company.gov”
”Smart.Manager@company.gov”
”Awesome.Boss@company.gov”;
*** The program below emails the notifying message to all clients;
%include "&thepath\Programs\EmailsFS.sas";
*** SELECT and SUBMIT the above step;
**********************************************************************;
*** END OF STEP X ***;
**********************************************************************;
The driving program manages the values of all variables as the email sender’s data, clients’ data by storing them into macro variables.
We do not recommend emailing sensible data using emails and that’s why the attachment option is omitted here.
Once all those variables are handled, the execution is done by the work program EmailsFS.sas.
Here is how it may look:
***************************************************************************;
*** TUNING THE EMAIL OPTIONS and EMAIL DEVICE ***;
*** CREATING THE MESSAGE and EMAILING TO ALL CLIENTS ***;
***************************************************************************;
*** check all clients and other recipients are properly recorded ***;
%put _user_;
*** setting up the EMAIL options ***;
options
EMAILHOST="mymail.server.com"
EMAILID="&myemail"
EMAILSYS=SMTP;
*** check the log for all options being properly set up ***;
proc options group=email;run;
*** tuning the EMAIL device options ***;
FILENAME outbox EMAIL
TO=(&clients)
CC=(&CCline)
SUBJECT="Monthly CHIP Reports Uploaded"
;
data _null_;
file outbox;
put "The monthly Reports are uploaded";
put "into your Secure FTP folder.";
put "&myname";
put "&myphone";
put "&myemail";
run;
*** EOF ***;
All of the macro variables are plugged into the proper options and that assures correct and immediate execution.
Once the values are correctly stored into the driving program, all of the work is reduced to a single click of the mouse.
CONCLUSION
This paper offers one of the many possible solutions on how to use the SAS EMAIL device. It can be very practical and time saving to implement it in the daily routine. Automation of the tedious work tasks is always fun and motivates for more creativity at work.
SAS Global Forum 2007 Coders’ Corner
REFFERENCES
SAS Institute Inc. 2002-2008 “SAS OnlineDoc® 9.1.3” Available at: http://support.sas.com/onlinedoc/913
ACKNOWLEDGMENTS
Special heartfelt thanks to Jim Moore, IT Technician at BCB-ORS for his helpful hints and guidance.
CONTACT INFORMATION
Your comments and questions are valued and encouraged. Contact the author:
Teo Gamishev
Office of Research and Statistics
1919 Blanding Street
Columbia, SC 29201
gamishev@hotmail.com
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS
Institute Inc. in the USA and other countries. ® indicates USA registration.
Other brand and product names are trademarks of their respective companies.
Download the PDF version from here
ABSTRACT
Setting up part of your email workload on autopilot from within SAS can eliminate the need of redundant work and significantly increase your job efficiency when dealing with repetitive tasks. SAS has built in emails generating engine, which when tuned properly, works very well with every email provider. Here you’ll find an example of fully automated process of emailing reports to several customers, using SAS.
INTRODUCTION
If you are emailing reports to your customers on a regular basis, then you definitely can benefit from the material laid out in this article. At least, it will motivate you to start testing, tweaking and having fun reading your first, successfully delivered emails. At the end you may end up using and enjoying this fully automated emailing system.
PROBLEMS
Here is a list of the problems covered on the following pages:
How to tune up your program to successfully deliver emails to a list of customers and supervisors;
How to generate the emails;
How to automate the entire process;
SOLUTIONS
TUNING UP SAS EMAIL ENGINE is not a rocket science, however I found it was not easy to locate the proper instructions on that. So, here is how it can be done:
EXAMPLE:
OPTIONS EMAILAUTHPROTOCOL=NONE
EMAILHOST=”mail.my.state”
EMAILID=”My.Name@MyCompany.com”
EMAILSYS=SMTP;
Email providers should be accessible from within the company without necessity of logging in and using a password. If that is not possible, then you should change the
EMAILAUTHPROTOCOL=LOGIN
After failing many times when trying to connect to my email provider, using the login protocol, our IT person gave me the hint of using a different host name to connect to it, without using user ID and password. You need to do your research and type the right hostname under EMAILHOST option, in order to assure smooth operation.
The EMAILID option contains your email address. If you just type a name or invalid email that may cause the email providers to filter out your messages or force them into the junk box. On another side, our email provider recognizes the fact that the sender and one of the recipients under the CC list are the same and refuses to deliver a copy of the emails to my Inbox. Your email provider may not be so smart, but you can always be creative here and use another email of yours to email a copy to yourself, if so needed.
The EMAILSYS option should be adjusted to SMTP(Simple Mail Transfer Protocol). The other possibilities are: MAPI(Messaging Application Program Interface) or VIM(Vendor Independent Messaging) . Those two may require login and password to access the server.
Here is how you tune your program for that:
OPTIONS EMAILAUTHPROTOCOL=LOGIN
EMAILHOST=”ciomail.my.state”
EMAILID="MyLogin" /* your email login */
EMAILPW="MyPass" /* your email password */
EMAILSYS=MAPI;
The fact that I have to type and leave sensitive information in my program doesn’t make me feel good about that. My advice is to move that entire OPTIONS statement into your AUTOEXEC.SAS file. However, make sure that your profile is in use every time when open a new SAS session. Not all servers, where SAS has been installed, are set up that way. Most of them will read the information in your AUTOEXEC.SAS during the first session and will skip it for the next sessions. Read the message into your log right after opening the second session. If you see the following message posted there, you will know that the OPTIONS statement and all other statements in the AUTOEXEC.SAS has not been activated. Copy and submit them from within your session, first.
NOTE: Unable to open SASUSER.PROFILE. WORK.PROFILE will be opened instead.
NOTE: All profile changes will be lost at the end of the session.
Once all of the above tuning is done, it is a good idea to check the options by submitting the following code:
proc options group=email; run;
GENERATING THE EMAILS from within SAS is an easy task to do. Let’s take a look at the example below:
EXAMPLE:
FILENAME outbox EMAIL
TO=”Perfect.Client@agency.gov”
CC=”Smart.Manager@company.com”
SUBJECT="Monthly Reports Uploaded"
;
data _null_;
file outbox;
put "Good Morning, ";
put " ";
put "The monthly Reports are uploaded";
put "into your Secure FTP folder.";
put " ";
put "Let me know if you have any questions. ";
put "Thank you and have a nice day";
put " ";
put "My Name";
put "ph:898-9999";
put "My.Email@company.com";
run;
There are two ways to address the recipient of the email:
By using the TO= option
FILENAME outbox EMAIL
TO=”Perfect.Client@agency.gov”
or
TO="My Customer
Or without using the TO= option and listing the recipient as an argument right after the EMAIL device type in the FILENAME statement:
FILENAME outbox EMAIL ”Perfect.Client@agency.gov”
Listing multiple recipients can be done by using the TO= option:
FILENAME outbox EMAIL
TO= (”Perfect.Client@agency.gov”
”Dream.Client@agency.gov”
”Polite.Client@agency.gov”)
In a similar way, multiple recipients can be listed under CC=:
CC= (”Best.Supervisor@company.gov”
”Smart.Manager@company.gov”
”Awesome.Boss@company.gov”)
Other useful options are:
FROM= /* your email */
BCC= /* recipient(s) that you want to receive a blind copy */
REPLYTO= /* who will receive replies */
SUBJECT= /* subject of the message */
ATTACH= /* physical name of the file(s) to be attached */
Make sure to enclose the SUBJECT= into double quotes, If the subject contains special characters or more than one word (that is, it contains at least one blank space).
EXAMPLE:
SUBJECT=Sales
or
SUBJECT="June Sales Report"
Note: If you do not enclose a one-word subject in quotation marks, it is converted to uppercase.
One or more files can be attached to the email:
EXAMPLE:
ATTACH=u/myfiles/report.txt"
or
ATTACH=('D:\Reports\June2001.txt' 'C:\Reports\July2001.txt')
or
ATTACH="user.misc.pds(member)"
AUTOMATING THE ENTIRE PROCESS can give you the flexibility to modify and the power to send the email(s) with a single click. All the variables can be controlled within a one program (driving program) and the execution of the emailing can be done from another program (work program). Below is an example on how that can be achieved:
1. The following code is located in the DRIVING program:
**********************************************************************;
*** STEP X ***;
*** EMAILING TO MY CUSTOMERS ***;
**********************************************************************;
*** PLEASE CHANGE THE DATA BELOW, AS NECESSARY;
*** reduces the hustle, when the programs are moved to a new server***;
%let thepath=D:\Projects\FS;
%let myemail=My.Name@MyCompany.com;
%let myname=My Name;
%let myphone=(803)888-7777;
%let clients=”Perfect.Client@agency.gov”
”Dream.Client@agency.gov”
”Polite.Client@agency.gov”;
%let CCline=”Best.Supervisor@company.gov”
”Smart.Manager@company.gov”
”Awesome.Boss@company.gov”;
*** The program below emails the notifying message to all clients;
%include "&thepath\Programs\EmailsFS.sas";
*** SELECT and SUBMIT the above step;
**********************************************************************;
*** END OF STEP X ***;
**********************************************************************;
The driving program manages the values of all variables as the email sender’s data, clients’ data by storing them into macro variables.
We do not recommend emailing sensible data using emails and that’s why the attachment option is omitted here.
Once all those variables are handled, the execution is done by the work program EmailsFS.sas.
Here is how it may look:
***************************************************************************;
*** TUNING THE EMAIL OPTIONS and EMAIL DEVICE ***;
*** CREATING THE MESSAGE and EMAILING TO ALL CLIENTS ***;
***************************************************************************;
*** check all clients and other recipients are properly recorded ***;
%put _user_;
*** setting up the EMAIL options ***;
options
EMAILHOST="mymail.server.com"
EMAILID="&myemail"
EMAILSYS=SMTP;
*** check the log for all options being properly set up ***;
proc options group=email;run;
*** tuning the EMAIL device options ***;
FILENAME outbox EMAIL
TO=(&clients)
CC=(&CCline)
SUBJECT="Monthly CHIP Reports Uploaded"
;
data _null_;
file outbox;
put "The monthly Reports are uploaded";
put "into your Secure FTP folder.";
put "&myname";
put "&myphone";
put "&myemail";
run;
*** EOF ***;
All of the macro variables are plugged into the proper options and that assures correct and immediate execution.
Once the values are correctly stored into the driving program, all of the work is reduced to a single click of the mouse.
CONCLUSION
This paper offers one of the many possible solutions on how to use the SAS EMAIL device. It can be very practical and time saving to implement it in the daily routine. Automation of the tedious work tasks is always fun and motivates for more creativity at work.
SAS Global Forum 2007 Coders’ Corner
REFFERENCES
SAS Institute Inc. 2002-2008 “SAS OnlineDoc® 9.1.3” Available at: http://support.sas.com/onlinedoc/913
ACKNOWLEDGMENTS
Special heartfelt thanks to Jim Moore, IT Technician at BCB-ORS for his helpful hints and guidance.
CONTACT INFORMATION
Your comments and questions are valued and encouraged. Contact the author:
Teo Gamishev
Office of Research and Statistics
1919 Blanding Street
Columbia, SC 29201
gamishev@hotmail.com
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS
Institute Inc. in the USA and other countries. ® indicates USA registration.
Other brand and product names are trademarks of their respective companies.
Subscribe to:
Comments (Atom)