spss.Submit Function (Python)

spss.Submit(command text). Submits the command text to IBM® SPSS® Statistics for processing. The argument can be a quoted string, a list, or a tuple.

  • The argument should resolve to one or more complete IBM SPSS Statistics commands.
  • For lists and tuples, each element must resolve to a string.
  • You can also use the Python triple-quoted string convention to specify blocks of IBM SPSS Statistics commands on multiple lines that more closely resemble the way you might normally write command syntax.
  • If IBM SPSS Statistics is not currently running (when driving IBM SPSS Statistics from Python), spss.Submit will start the IBM SPSS Statistics backend processor.
  • Submitted syntax for MATRIX-END MATRIX and BEGIN DATA-END DATA blocks cannot be split across BEGIN PROGRAM-END PROGRAM blocks.
  • The following commands are not supported by Submit when driving IBM SPSS Statistics from Python: OUTPUT EXPORT, OUTPUT OPEN and OUTPUT SAVE.

Example

BEGIN PROGRAM.
import spss
#run a single command 
spss.Submit("DISPLAY NAMES.")  
#run two commands
spss.Submit(["DISPLAY NAMES.", "SHOW $VARS."])  

#build and run two commands
command1="FREQUENCIES VARIABLES=var1." 
command2="DESCRIPTIVES VARIABLES=var3."
spss.Submit([command1, command2])
END PROGRAM.

Example: Triple-Quoted Strings

BEGIN PROGRAM.
import spss
file="/examples/data/demo.sav"
varlist="marital gender inccat"
spss.Submit("""
GET FILE='%s'.
FREQUENCIES VARIABLES=%s
  /STATISTICS NONE
  /BARCHART.
""" %(file,varlist))
END PROGRAM.

Within the triple-quoted string, %s is used for string substitution; thus, you can insert Python variables that resolve to strings in the quoted block of commands.