Leonid,

Nice blog post! Thanks for the cogent use case and explanation. As a slight alternative to your approach, for those that might want to constrain resource usage on a shared machine, your shell script can be modified to use the xargs command to implement a process pool (akin to a thread pool) and limit the number of concurrent processes running SAS jobs.

Your approach will run as many processes as there are days in the month, yes? It sounds like that is producing good parallelism. The approach , however, might overwhelm the machine if the number of SAS jobs and processes is larger. To restrict the number of processes, you can replace the for loop and wait command with a call to xargs, for which the number of concurrent processes can be set. Specifically, replace the code from "for i in" through "wait" with something like this:

# use xargs to to run multiple SAS processes
# but limit number of processes to 5, for example
N_PROCS=5
# limit number of days for each process
M_DAYS=$(( days / N_PROCS + 1 ))
seq -f "%02g" 1 $days | xargs --max-procs ${N_PROCS} --max-args ${M_DAYS} ./month_parallel_worker.sh "$logdir" "$prgm" "$y" "$m" "$now" "$pgmname" "$par"

and then create a new script "month_parallel_worker.sh" like this:

#!/bin/sh

# HOW TO RUN:
# month_parallel_worker.sh logdir prgm y m now pgmname par [ day [ day [ ... ] ] ]

if [ $# -lt 7 ]
then
# ERROR: Insufficient number of arguments
exit 1
fi

logdir=$1
prgm=$2
y=$3
m=$4
now=$5
pgmname=$6
par=$7
shift 7

# Run one or more SAS jobs sequentially
while [ $# -gt 0 ]
do

i="$1"

# Assign log name for a single day thread
logname=$logdir/${prgm}_${y}${m}_thread${i}_$now.log

# Run single day thread
/SASHome/SASFoundation/9.4/sas $pgmname -log $logname -sysparm $par$i

shift

done

Here, the number of processes is limited to 5 but this can be easily varied.