DATA Step, Macro, Functions and more

Execute SAS using command line

Posts: 59

Execute SAS using command line



I'm trying to create a shell script to execute SAS in command line. The objetive is use it to run SAS programns in crontab. The shell script created use two parameters, $1 and $2. The first parameter ($1) is the complete path of SAS program to execute and the second one ($2) is the user's name of the responsible.




$ which sasprogram
$ more /usr/bin/sasprogram

umask 007

PATH=.Smiley Surprisedpt/bin:/bin:/usr/sbin:/usr/bin:/usr/ccs/bin:/GNU/bin/make:/usr/ucb:/sas/software/SASFoundation/9.2/bin
export PATH

progpath=`dirname "$1"`

prog=`basename "$1"`

cd $progpath

nohup /<path>/BatchServer/ -log /<path>/logs/$prog.#Y_#m_#d.log -batch -noterminal -logparm "rollover=session" -xcmd -autoexec /<path>/ -sysparm "$1|$2" &



I'm using the following command line to execute:

sasprogram /<path>/ UserName



After run, log file is empty as shown below:

$ cat /<path>/logs/

NOTE: Log file opened at Mon, 26 Jun 2017 16:11:58.754


And in nohup.out log the following message appears:

$ cat nohup.out

/<path>/[46]: UserName:  not found


Any ideia what is going on?




Super User
Posts: 6,948

Re: Execute SAS using command line

Inspect line 46 of to see why Username ends up being taken for a UNIX command.

What I see is that in your call to you do not supply the program path and name. You set the log and the autoexec, but there's no -sysin or equivalent. That is the reason for the empty log.

Maxims of Maximally Efficient SAS Programmers
Super User
Super User
Posts: 6,502

Re: Execute SAS using command line

Looks like you have bug in the program that your program is calling. Most likely it is not properly transfering its input parameters onto the SAS executable.  In particular it looks like quotes around the pipe character in the value of -sysparm option are not being honored and so UserName is being interpretted by the shell as the name of the program to pipe the output of the SAS job into.  Is it passing the parameters using "$@" ?


You could try calling it with \| instead of | to protect the pipe character, but I think you probably need to fix that other script.

Ask a Question
Discussion stats
  • 2 replies
  • 1 like
  • 3 in conversation