Streamline the Process - A Real Life Example Yadong Zhang, Oxford Health Plans, Trumbull, CT ABSTRACT This paper presents a real life example on the evolution of a A SHELL SCRIPT TO THE RESCUE monthly report application. The application uses SAS/SQLâ pass â Now you get the DBF report that needs to be sent to the through and Base SAS to develop report and email the final business user. In our case, we run SAS on a UNIX box, product to the end user. The application also archives the log and our business users are on an NT server. So we and report automatically. either FTP the report to a shared place, or if the file is small enough, we email it to the user. That's exactly INTRODUCTION what I did in the first two runs: I FTP’d the file to my PC It is common for a SAS programmer to develop reports running and emailed it as an attachment. Tedious and time on a regular basis. How do you simplify the process? How do consuming, I began to hate it the third time I did it. So I you make your program to do the 'thinking' for you? This paper called on a shell script to the rescue. will present some tips on this subject. report.sh #!/bin/ksh PROBLEM # Declare shell variables On the first day of each month, produce a report on transitional ¶PGMDIR=/project/pgms care in DBF format, using tables on an Oracleâ data warehouse. ·PROG=report ¸RPTDATE="`date '+%Y-%m-%d'`" SOLUTION ¹ADM="yzhang@exchange-server" ºMAILTO="USER1@exchange-server As always, there is more than one way to do it in SAS. For this yzhang@exchange-server" project, I chose to use SAS/SQL pass through to subset and pull »export PGMDIR RPTDATE ADM MAILTO the data down and SAS to generate the DBF report. # Call SAS program report.sas ¼/sashome/sas $PGMDIR/$PROG -log $PGMDIR -print PROC SQL; $PGMDIR ¶CONNECT TO ORACLE AS MYDB (USER=YZHANG ORAPW=#### PATH="####"); # Error Handling and House Keeping ½if [ $? -gt 0 ]; then ·EXECUTE (CREATE OR REPLACE VIEW YZHANG.TRANS AS ¾ mailx -s "ERROR running trans rpt" $ADM SELECT * FROM ORACLE_TABLE_1 else WHERE WHERE_CLAUSE )) BY MYDB; ¿cp $PGMDIR/$PROG.log $PGMDIR/backup/$PROG.log.$RPTDATE ¸CREATE TABLE TRANS AS SELECT * FROM CONNECTION TO MYDB ( ¶¶uuencode transition.xls < $PGMDIR/REPORT.DBF SELECT * FROM YZHANG.TRANS); | mailx -s "Transition report on $RPTDATE" $MAILTO fi ¹CREATE TABLE CLAIM AS exit 0 SELECT * FROM CONNECTION TO MYDB ( SELECT * FROM ORACLE_TABLE_2 ¶ Program directory WHERE ID IN · Program name without extension .sas (SELECT DISTINCT ID FROM YZHANG.TRANS)); ¸ Define RPTDATE as system date in 'YYYY-MM-DD' QUIT; format ¹ Internal Email address of programmer … more data steps º Internal Email address of user » Export all variables to environment ºPROC DBF DB4=REPORT DATA=FINAL; ¼ Launch report.sas. Redirect log and print to program RUN; directory. /sashome is root directory for SAS executable ¶ Connect to database as 'MYDB' ½ Korn shell variable $? is the exit status of the last · Modified in second run from 'CREATE TABLE'. In Oracle SQL, command that ran. 0 is 'OK', while anything else there is no 'CREATE OR REPLACE TABLE', you have to drop a usually denotes an error. table first in order to recreate it. Fortunately, there is ' CREATE ¾ If there is error running report.sas, send an email to OR REPLACE VIEW'. programmer. ¸ Download to a SAS data set. Syntax for UNIX mail utility mailx: ¹ Create another SAS data set by using sub-query on Oracle mailx [-s subject] [other options] recipient. º Write out REPORT.DBF ¿ Archive report.log to backup directory. ¶¶ Email the report to users. UNIX utility uuencode converts a binary file into an encoded representation that can be send using mailx. Syntax: uuencode [ source-file ] decode_pathname. CONTACT INFORMATION Your comments and questions are valued and The compound command encodes REPORT.DBF and mails it encouraged. Contact the author at: as an attachment-transition.xls. Yadong Zhang Oxford Health Plans Please note that although the attachment has an extension of 48 Monroe Turnpike xls, the file is still in DBF format. The xls extension tricks Trumbull, CT 06611 â â Windows to believe the file is an Excel file, so the user can (203) 459-7416 open it directly. [email protected] JOB SCHEDULING Now you have the shell script to run the SAS program and then email the report to the user. All you have to do is type report.sh at the Unix Prompt the first day of each month. And I know what's on your mind, if you are as lazy as I am, you want the computer to handle this part too. Lucky for us, the UNIX command crontab is designed for this. Syntax: crontab crontab_file A crontab file is a list of commands, one per line, which will execute automatically at a given time. It looks as follows: minute hour day_of_month month day_of _week command For example 0 6 1 * * /project/pgms/report.sh run report.sh at 6:00 am on the 1st of each month. Now we are happy. CONCLUSION SAS used with UNIX shell scripting is a very powerful combination. It can make your life much easier. REFERENCES SAS Institute Inc., “SAS/Accessâ Reference, Version 6, First Edition,” Cary NC: SAS Institute Inc. Daniel Gilly (1997), “UNIX in a Nutshell, System V Edition,” O'Reilly & Associates, Inc. ACKNOWLEDGMENTS The author would like to thank Gina Stover and Terri Halasz for their assistance in this paper. TRADEMARK SAS, SAS/SQL are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Other brand and product names are registered trademarks or trademarks of their respective companies..
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages2 Page
-
File Size-