[Tutor] executing SAS and passing parameters

Terry Carroll carroll at tjc.com
Thu Feb 10 02:41:33 CET 2005

I'd echo what Alan said.  It sounds more like you're having trouble 
finding out what the command line to SAS should look like, rather than 
invoking it with Python.

(I'm going to quote some of your message out-of-order to better facilitate 
my approach to this.  I will, I trust, not misrepresent the context.)

On Wed, 9 Feb 2005, Williams, Thomas wrote:

> However, the program in question is c:\work\run_ratios.sas, with 2
> parameters: incov, and outcov.  This program was initially invoked from an
> aml program.  The code that invoked SAS from this aml is:
> 	&SYSTEM %.SASLOC% -SYSPARM %sas_parm% -log ~
> %.ARCLOC%\ratios\log\%.file%.log -SYSIN ~
> %.ARCLOC%\sas_code\ratios\new_ratio.sas
> %.SASLOC%: the SAS executable file ('C:\Program Files\SAS
> Institute\SAS\V8\SAS.exe')
> %sas_parm%: the list of parameters to be passed onto SAS
> %.file%: the name of the log file that is generated during the execution of
> the SAS program.
> %.ARCLOC%: directory of the SAS program (c:\work)

First, something's not jibing here: you say the program to run is 
c:\work\run_ratios.sas , but none of the variables under AML appear to 
have "run_ratios" in it. (Not that I know what AML is).

My expectation is that this code:

> 	&SYSTEM %.SASLOC% -SYSPARM %sas_parm% -log ~
> %.ARCLOC%\ratios\log\%.file%.log -SYSIN ~
> %.ARCLOC%\sas_code\ratios\new_ratio.sas

Expands to an invocation of this:

C:\Program Files\SAS Institute\SAS\V8\SAS.exe -SYSPARM incov outcov 
-log c:\work\ratios\log\[logfilename].log
-SYSIN  c:\work\sas_code\ratios\new_ratio.sas

(where [logfilename] is actually replaced with the name of your logfile.)

As I said, no reference to "c:\work\run_ratios.sas" in this; so confirm 

My suggestion is that you open up an MSDOS window, and try variations on 
this until you find one that works.  Once you find one that works, you 
know your command; and that's going to be 95% of the battle.

In your Python code:

> 	os.execl('C:\Program Files\SAS Institute\SAS\V8\SAS.exe')

First, as Alan points out, try os.system() instead.  I would also very 
much encourage a piece of advice he gave that might have slipped through, 
which is: build a string, first, and pass that string to os.system().  
That way, you can do some debugging by making sure your string represents 
the command you cane up with earlier.

I'd also recommend using forward slashes rather than backslashes,  which 
saves you some escape heartache.  Forward slashes should still work.

You can also do something along the same lines your AML took, if 
you like:

SAS_location = "C:/Program Files/SAS Institute/SAS/V8/SAS.exe"
sas_parm = "incov outcov"
ARC_location = "c:/work/"
logfile = "ratios/mylog.log"
SAS_SYSIN = "sas_code/ratios/new_ratio.sas"

command_line = "%s -SYSPARM %s -log %s%s -SYSIN %s%s" % (SAS_location, sas_parm,
 ARC_location, logfile, ARC_location, SAS_SYSIN)

print command_line
# above line verifies the command matches what you determined from the 
# earlier testing from the MS-DOS command line

# invoke SAS

More information about the Tutor mailing list