1. AJ R
  2. savReaderWriter


savReaderWriter / savReaderWriter / documentation / index.rst

Welcome to savReaderWriter's documentation!

In the documentation below, the associated SPSS commands are given in CAPS. See also the IBM SPSS Statistics Command Syntax Reference.pdf for info about SPSS syntax.


This program works for Linux (incl. z/Linux), Windows, MacOS (32 and 64 bit), AIX-64, HP-UX and Solaris-64. However, it has only been tested on Linux 32 (Ubuntu and Mint), Windows (mostly on Windows XP 32, but also a few times on Windows 7 64), and MacOS (with an earlier version of savReaderWriter). The other OSs are entirely untested. The program can be installed by running:

python setup.py install

Or alternatively:

pip install savReaderWriter

To get the 'bleeding edge' version straight from the repository do:

pip install -U -e git+https://bitbucket.org/fomcl/savreaderwriter.git#egg=savreaderwriter

The savReaderWriter program is now self-contained. That is, the IBM SPSS I/O modules now all load by themselves, without any changes being required anymore to PATH, LD_LIBRARY_PATH and equivalents. Also, no extra .deb files need to be installed anymore (i.e. no dependencies).

The cWriterow package is a faster Cython implementation of the pyWriterow method. To install it, you need Cython and run setup.py in the cWriterow folder:

easy_install cython
python setup.py build_ext --inplace

:mod:`SavWriter` -- Write Spss system files

Typical use:

savFileName = "someFile.sav"
records = [['Test1', 1, 1], ['Test2', 2, 1]]
varNames = ['var1', 'v2', 'v3']
varTypes = {'var1': 5, 'v2': 0, 'v3': 0}
with SavWriter(savFileName, varNames, varTypes) as writer:
    for record in records:

:mod:`SavReader` -- Read Spss system files


Once a file is open, ioUtf8 and ioLocale can not be changed. The same applies after a file could not be successfully closed. Always ensure a file is closed by calling __exit__() (i.e., using a context manager) or close() (in a try - finally suite)

Typical use:

savFileName = "someFile.sav"
with SavReader(savFileName, returnHeader=True) as sav:
    header = sav.next()
    for line in sav:

Use of __getitem__ and other methods:

data = SavReader(savFileName, idVar="id")
with data:
    print "The file contains %d records" % len(data)
    print unicode(data)  # prints a file report
    print "The first six records look like this\n", data[:6]
    print "The first record looks like this\n", data[0]
    print "The last four records look like this\n", data.tail(4)
    print "The first five records look like this\n", data.head()
    print "First column:\n", data[..., 0]  # requires numpy
    print "Row 4 & 5, first three cols\n", data[4:6, :3]  # requires numpy
    ## ... Do a binary search for records --> idVar
    print data.get(4, "not found")  # gets 1st record where id==4

:mod:`SavHeaderReader` -- Read Spss file meta data


The program calls spssFree* C functions to free memory allocated to dynamic arrays. This previously sometimes caused segmentation faults. This problem now appears to be solved. However, if you do experience segmentation faults you can set segfaults=True in __init__.py. This will prevent the spssFree* functions from being called (and introduce a memory leak).

Typical use:

with SavHeaderReader(savFileName) as spssDict:
    wholeDict = spssDict.dataDictionary()
    print unicode(spssDict)