1

I'm trying to retrieve data from my SPSS output in python, so i can modify the data and write it to excel. I've got no problem retrieving the data from a descriptives table using the following code:

import spssaux
variables = 'Age'
vDict = spssaux.VariableDict(caseless=True)
vList = vDict.expand(variables)
cmd = spssaux.CreateXMLOutput('descriptives %s.'%" ".join(vList))
ageMax = spssaux.GetValuesFromXMLWorkspace(cmd,'Descriptive Statistics',colCategory = 'Maximum',cellAttrib = 'number')
ageMax = int(ageMax[0])
print(ageMax)

But when I want to extract data from a frequency table i'm not able to retrieve any data.

I've tried to use the "OMS logic" (names of Table subtype or labels) but still no result. I'm using SPSS Statistics 26.

This is (some of) the code i've tried so far:

import spssaux
variables = 'Age'
vDict = spssaux.VariableDict(caseless=True)
vList = vDict.expand(variables)
cmd = spssaux.CreateXMLOutput('fre %s.'%" ".join(vList))
agePercentage1 = spssaux.GetValuesFromXMLWorkspace(cmd,'Frequencies',colCategory = 'Valid Percent')
agePercentage1 = agePercentage1[0]
print(agePercentage1)

Hopefully somebody can help me.

Kind regards, Bart

  • Not sure I can help with capturing with python, but just to make sure - are you aware that you can capture the output data to a new dataset and modify it there all with regular syntax? (using OMS control panel) – eli-k Mar 04 '22 at 12:22
  • Thank you for your reply eli-k. I'm familiar with OMS but unfortunately I think OMS is in this case not sufficient. I've used OMS in other cases but now I need the data in python. I want to modify the data and combine it with other data formats. And eventually write and format the data into excel files. This going to be an automated process. Therefore Python is a bit more flexible. – Bart van Wensen Mar 04 '22 at 14:34

0 Answers0