SPSS calls python (5): reading of output results

SPSS is very powerful, it can output a very large amount of statistical information, but sometimes we don't need that much information, we just need that little bit of information, then we can output the specified information in the output screen through Python.

BEGIN PROGRAM.

import spss,spssaux

cmd="DESCRIPTIVES VARIABLES=salary,salbegin,jobtime,prevexp."

desc_table,Errcode=spssaux.CreateXMLOutput(

cmd,

omsid="Descriptives")

meansal=spssaux.getValuesFromXMLWorkspace(

desc_table,

tableSubtype="Descriptive Statistics",

rowCategory="Current Salary",

colCategory="Mean",

cellAttrib="text")

if meansal:

print "The average salary is: ", meansal[0]

END PROGRAM.

At this point we can see that the output screen is

The average salary is: $34,419.57

If we want to know the starting salary, we just need to change the code

BEGIN PROGRAM.

import spss,spssaux

cmd="DESCRIPTIVES VARIABLES=salary,salbegin,jobtime,prevexp."

desc_table,Errcode=spssaux.CreateXMLOutput(

cmd,

omsid="Descriptives")

meansal=spssaux.getValuesFromXMLWorkspace(

desc_table,

tableSubtype="Descriptive Statistics",

rowCategory="Beginning Salary",

colCategory="Mean",

cellAttrib="text")

if meansal:

print " The starting salary is: ", meansal[0]

END PROGRAM.

At this point you can see that it is

Starting salary is: $17,016.09

Once we understand this functionality, we can design our own programs to output the results we want, which is one of the basic skills for designing your own extension bundle