Working with Python Program Blocks
Use SET PRINTBACK ON MPRINT ON
to display the
syntax generated by program blocks.
Example
SET PRINTBACK on MPRINT on.
* Get the employee data.sav file from samples/english under the SPSS installation directory and run the following code.
BEGIN PROGRAM PYTHON3.
import spss
scaleVarList=[]
catVarList=[]
varcount=spss.GetVariableCount()
for i in range(varcount):
if spss.GetVariableMeasurementLevel(i) == 'scale':
scaleVarList.append(spss.GetVariableName(i))
elif spss.GetVariableMeasurementLevel(i) in ['nominal', 'ordinal']:
catVarList.append(spss.GetVariableName(i))
if catVarList:
spss.Submit(f"""FREQUENCIES
/VARIABLES={" ".join(catVarList)}""")
if scaleVarList:
spss.Submit(f"""DESCRIPTIVES
/VARIABLES={" ".join(scaleVarList)}""")
END PROGRAM.
The generated command syntax is displayed in the log in the IBM® SPSS® Statistics Viewer:
225 M> FREQUENCIES
226 M> /VARIABLES=gender educ jobcat minority.
227 M> DESCRIPTIVES
228 M> /VARIABLES=id bdate salary salbegin jobtime prevexp.