Popular recipes tagged "pasw"http://code.activestate.com/recipes/tags/pasw/2011-07-25T18:59:49-07:00ActiveState Code RecipesPython reader for spss sav files (Python)
2011-07-25T18:59:49-07:00Albert-Jan Roskamhttp://code.activestate.com/recipes/users/4177640/http://code.activestate.com/recipes/577650-python-reader-for-spss-sav-files/
<p style="color: grey">
Python
recipe 577650
by <a href="/recipes/users/4177640/">Albert-Jan Roskam</a>
(<a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/pasw/">pasw</a>, <a href="/recipes/tags/sav/">sav</a>, <a href="/recipes/tags/spss/">spss</a>, <a href="/recipes/tags/statistics/">statistics</a>).
Revision 3.
</p>
<p><strong>Python Program to read Spss system files (.sav)</strong></p>
<ul>
<li><em>* version 2 (FASTER!) *</em></li>
<li>Requires spssio32.dll, which can be freely downloaded from:
<a href="https://www.ibm.com/developerworks/mydeveloperworks/wikis/home/wiki/We70df3195ec8_4f95_9773_42e448fa9029/page/Downloads%2520for%2520IBM%25C2%25AE%2520SPSS%25C2%25AE%2520Statistics?lang=en" rel="nofollow">https://www.ibm.com/developerworks/mydeveloperworks/wikis/home/wiki/We70df3195ec8_4f95_9773_42e448fa9029/page/Downloads%20for%20IBM%C2%AE%20SPSS%C2%AE%20Statistics?lang=en</a></li>
<li>You can also find this dll in the installation directory of SPSS (although SPSS is _not_ needed!)</li>
<li><p>The .dll should be saved in the same location as this program.</p></li>
<li><p>Parameters:
<em>savFileName</em>: the file name of the spss data file;
<em>returnHeader</em>: Boolean that indicates whether the first record
should be a list of variable names (default: True);
<em>recodeSysmisTo</em>: indicates to which value missing values should
be recoded (default: "");
<em>selectVars</em>: indicates which variables in the file should be
selected.The variables should be specified as a list or a tuple
of valid variable names. If None is specified, all variables
in the file are used (default: None);
<em>verbose</em>: Boolean that indicates whether information about the
spss data file (e.g., number of cases, variable names, file
size) should be printed on the screen (default:
True). <br />
<em>rawMode</em>: Boolean that indicates whether values should get
SPSS-style formatting,and whether date variables (if present)
should be converted to ISO-dates. If True, the program does not
format any values, which increases processing speed. (default:
= False)
<em>interfaceEncoding</em> Indicates the mode in which text communicated
to or from the I/O Module will be. Valid values are 'UTF-8' or
'CODEPAGE' (default = 'CODEPAGE')</p></li>
<li><p>Typical use:
savFileName = "d:/someFile.sav"
with SavReader(savFileName) as sav:
header = sav.next()
for line in sav:
process(line)</p></li>
<li><p>Note:
--<em>New version</em>: If you downloaded this previously, use the current version as it is <strong>MUCH faster!!</strong>
--this code currently only works on Windows (32 bits). I might make it work on Linux Ubuntu 10 at some point.
--date fields in spss are represented as the number of seconds since the Gregorian calendar. The program converts these, wherever possible, to ISO-dates (yyyy-mm-dd).</p></li>
</ul>
<p>Any feedback is welcome! I'm still learning!</p>