Date: Mon, 7 Jan 2002 16:20:19 -0000
Reply-To: Philip Mason <philipmason@WOODSTREET.ORG.UK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Philip Mason <philipmason@WOODSTREET.ORG.UK>
Subject: SASTip: Simple program scheduler using a SAS macro
Content-Type: text/plain; charset="us-ascii"
This is *simple* program scheduling tool, implemented using a macro. It
was written on Windows XP running SAS 8.2. I'm sure it can be greatly
improved, but it does demonstrate some useful basic techniques.
It has these features:
- uses a dataset to list programs to run in sequence
- records return codes and start/end times
- Provides a good basis for adding extra features, such as
- Scheduling programs to run at particular times
- Using a GUI for setting up dataset with jobs to run and to change
sequence
- Use of multiple processes via SAS/Connect
To use follow these 3 steps:
1) Create jobs dataset
- holds names of programs to run
- Programs are in the sequence in which they should run
- Fields defined for start/end datetime values, return code from
program, system message from program
------- code -------
data sasuser.jobs ;
length location $ 200
start end 8
rc 4
msg $ 200 ;
format start end datetime. ;
input location ;
put location= ;
return ;
cards;
c:\temp\prog1.sas
c:\temp\prog2.sas
;;;;
run ;
--------------------
2) Define the controller macro, which uses jobs dataset to determine
what to run next
------- code -------
%macro controller ;
data sasuser.results ;
format start end datetime. ;
set sasuser.jobs ;
run ;
%let dsid=%sysfunc(open(sasuser.jobs,i)) ;
%syscall set(dsid) ;
%let n=0 ;
%do %while(%sysfunc(fetch(&dsid))=0) ;
%let n=%eval(&n+1) ;
%let start=%sysfunc(datetime()) ;
%include "&location" ;
%let end=%sysfunc(datetime()) ;
data sasuser.results ;
set sasuser.results ;
if _n_=&n then
do ;
start=&start ;
end=&end ;
rc=symget('sysrc') ; *may not be best source of rc;
msg=symget('sysmsg') ;
end ;
run ;
%end ;
%let dsid=%sysfunc(close(&dsid)) ;
%mend controller ;
--------------------
3) Run it
%controller
Philip Mason - www.woodstreet.org.uk - philipmason@woodstreet.org.uk