DATA Step, Macro, Functions and more

Execute SAS using command line

Reply
Contributor
Posts: 69

Execute SAS using command line

Hi,

 

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.

 

Shell

--------

##
$ which sasprogram
/usr/bin/sasprogram
$ more /usr/bin/sasprogram
#!/bin/sh

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/sasbatch.sh -log /<path>/logs/$prog.#Y_#m_#d.log -batch -noterminal -logparm "rollover=session" -xcmd -autoexec /<path>/autoexec.sas -sysparm "$1|$2" &
$
##

----

 

I'm using the following command line to execute:

sasprogram /<path>/SAScode.sas UserName

 

 

After run, log file is empty as shown below:

$ cat /<path>/logs/SAScode.sas.2017_06_26.log

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>/sasbatch.sh[46]: UserName:  not found

 

Any ideia what is going on?

 

Regards,

 

Super User
Posts: 7,760

Re: Execute SAS using command line

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

What I see is that in your call to sasbatch.sh 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: 7,039

Re: Execute SAS using command line

Looks like you have bug in the sasbatch.sh 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
  • 252 views
  • 1 like
  • 3 in conversation