So my assumption is that all the programs that build your intermediate datasets are in their own library called "idsbuild". Of course, it won't be like that where you are, but I hope you will be able to follow my logic and adapt it to your own site. I am going to assume that you have all sorts of test programs in the directory that hosts the real programs that build your intermediate datasets. And that all the "real" programs begin with an "a", "b" or "c" and are immediately followed by a numeric digit in the program name. That may not fit your site but you need to know the techniques for picking out your programs based on criteria like this. In the case of the above, where a SAS program begins with either "a", "b" or "c" and is immediately followed by a numeric digit then this command will list them all:
ls [a,b,c][0-9]*.sas
(You are learning about "file name matching" which is something different to "pattern matching" in Unix and this is a very important thing to learn. I will only teach you how to "walk" with scripts. Learning how to "run" is something I am leaving you to learn on your own).
So let's think about what we want our script to do. This program suite will be creating intermediate dataset so we will want to delete these intermediate datasets before we start. We will also want to delete any log and list files for these programs. And if any of these log or list files or intermediate datsets do not already exist then we are not bothered about it so we can route any error messages to the Unix dustbin /dev/null . We are going to generate the script to do this. So the generated script should explain that it has been generated so that people do not amend it because the next time it is generated their version will get wiped out. Presumably some "raw" datasets exist in a directory. Let us suppose we have a root directory defined to the environment variable RD (environment variables shoudl always be uppercase) and that our protocol is the next on the directory and the study is next and that our raw data is in the "raw" directory underneath that then this would be a script to generate the script to build all your intermediate datasets. There is another thing. If any of these intermediate dataset build programs fail then we had better abandon the rest since it is not going to work for the tables and listings programs at some stage. Better to abandon the rest if this happens.
Please take time to study the following script. Feel free to amend it. It won't try to run the programs unless you launch it. One day you will be asked to write a script like this.
#!/bin/sh
# Script : mkbuild
# Version : 1.0
# Author : Roland Rashleigh-Berry
# Date : 06 August 2003
# Contact : rolandberry@hotmail.com
# Purpose : To create the script for building intermediate datasets
# SubScripts : none
# Notes : Make the directory with the intermediate dataset build programs in
# the current directory before invoking this script.
# Usage : mkbuild
#
#================================================================================
# PARAMETERS:
#-pos- -------------------------------description--------------------------------
# N/A (none)
#================================================================================
# AMENDMENT HISTORY:
# init --date-- mod-id ----------------------description-------------------------
#
#================================================================================
# This is public domain software. No guarantee as to suitability or accuracy is
# given or implied. User uses this code entirely at their own risk.
#================================================================================
proj=`pwd | sed "s%$RD%%" | awk -F/ '{print $2}'`
prot=`pwd | sed "s%$RD%%" | awk -F/ '{print $3}'`
rm -f build 2>/dev/null
ls -1 [a,b,c][a-z]*.sas 2> /dev/null | awk -F. '{print $1}' | sort > $HOME/progs.tmp
if [ -s $HOME/progs.tmp ] ; then
cat > build << FINISH
#!/bin/sh
# This script was automatically generated by the "mkbuild" utility. Do not edit this
# member as it will likely be overwritten by the same utility that created it.
echo \$USER \`date\` 1>&2
# Delete the output datasets
rm $RD/$proj/$prot/ids/*.sas7bdat 2> /dev/null
# Delete the .log and .lst files
rm [a,b,c][a-z]*.log 2>/dev/null
rm [a,b,c][a-z]*.lst 2>/dev/null
# Run each program and exit if there is an error.
FINISH
#==============================================================
exec < $HOME/progs.tmp
while read prog
do
#==============================================================
cat >> build << FINISH
# Program: $prog
sas -sasuser work -sysin $prog
if [ \$? -gt 0 ] ; then exit 2 ; fi
FINISH
#==============================================================
done
echo "echo 'finished' 1>&2" >> build
# Make "build" an executable file
chmod +x build
fi
#!/bin/sh
# Script : mkrep
# Version : 1.0
# Author : Roland Rashleigh-Berry
# Date : 06 August 2003
# Contact : rolandberry@hotmail.com
# Purpose : To create the script for running reports
# SubScripts : intitles
# Notes : Make the directory with the report code in the current directory
# before invoking this script. This assumes the "intitles" script
# has been written.
# Usage : mkrep
#
#================================================================================
# PARAMETERS:
#-pos- -------------------------------description--------------------------------
# N/A (none)
#================================================================================
# AMENDMENT HISTORY:
# init --date-- mod-id ----------------------description-------------------------
#
#================================================================================
# This is public domain software. No guarantee as to suitability or accuracy is
# given or implied. User uses this code entirely at their own risk.
#================================================================================
proj=`pwd | sed "s%$RD%%" | awk -F/ '{print $2}'`
prot=`pwd | sed "s%$RD%%" | awk -F/ '{print $3}'`
rm -f rep 2>/dev/null
intitles > $HOME/progs.tmp
if [ -s $HOME/progs.tmp ] ; then
cat > rep << FINISH
#!/bin/sh
# This script was automatically generated by the "mkrep" utility. Do not edit this
# member as it will likely be overwritten by the same utility that created it.
echo \$USER \`date\` 1>&2
# Delete the output datasets
rm *.lst 2> /dev/null
rm *.log 2> /dev/null
# Run each program in turn.
FINISH
#==============================================================
exec < $HOME/progs.tmp
while read prog
do
#==============================================================
cat >> build << FINISH
# Program: $prog
sas -sasuser work -sysin $prog
FINISH
#==============================================================
done
echo "echo 'finished' 1>&2" >> rep
# Make it an executable file
chmod +x rep
fi
#!/bin/sh
# Script : runsuite
# Version : 1.0
# Author : Roland Rashleigh-Berry
# Date : 06 August 2003
# Contact : rolandberry@hotmail.com
# Purpose : To run the intermediate dataset build plus report build
# SubScripts : mkbuild mkrun
# Notes : Make the directory with the report code in the current directory
# before invoking this script.
# Usage : sh runsuite
#
#================================================================================
# PARAMETERS:
#-pos- -------------------------------description--------------------------------
# N/A (none)
#================================================================================
# AMENDMENT HISTORY:
# init --date-- mod-id ----------------------description-------------------------
#
#================================================================================
# This is public domain software. No guarantee as to suitability or accuracy is
# given or implied. User uses this code entirely at their own risk.
#================================================================================
proj=`pwd | sed "s%$RD%%" | awk -F/ '{print $2}'`
prot=`pwd | sed "s%$RD%%" | awk -F/ '{print $3}'`
cd $RD/$proj/$prot/programs/build
mkbuild
sh build 1>build.msg 2>build.err
if [ $? -gt 0 ] ; then exit 2 ; fi
cd $RD/$proj/$prot/programs/efficacy
mkrun
sh run 1>run.msg 2>run.err &
cd $RD/$proj/$prot/programs/safety
mkrun
sh run 1>run.msg 2>run.err &
echo "Finished"
Go back to the home page.
E-mail the macro and web site author.