Popular recipes tagged "spss"http://code.activestate.com/recipes/tags/spss/2014-02-17T20:53:56-08:00ActiveState Code Recipessav2mdb (Python)
2014-02-17T20:53:56-08:00Albert-Jan Roskamhttp://code.activestate.com/recipes/users/4177640/http://code.activestate.com/recipes/578826-sav2mdb/
<p style="color: grey">
Python
recipe 578826
by <a href="/recipes/users/4177640/">Albert-Jan Roskam</a>
(<a href="/recipes/tags/access/">access</a>, <a href="/recipes/tags/spss/">spss</a>).
Revision 2.
</p>
<p>sav2mdb.py: convert SPSS system files (codepage) to Microsoft Access files</p>
Python reader + writer for spss sav files (Linux, Mac & Windows) (Python)
2013-02-20T22:07:27-08:00Albert-Jan Roskamhttp://code.activestate.com/recipes/users/4177640/http://code.activestate.com/recipes/577811-python-reader-writer-for-spss-sav-files-linux-mac-/
<p style="color: grey">
Python
recipe 577811
by <a href="/recipes/users/4177640/">Albert-Jan Roskam</a>
(<a href="/recipes/tags/reader/">reader</a>, <a href="/recipes/tags/sav/">sav</a>, <a href="/recipes/tags/spss/">spss</a>, <a href="/recipes/tags/writer/">writer</a>).
Revision 12.
</p>
<p><strong>Python Program to READ & WRITE Spss system files (.sav) (Linux,Mac or Windows)</strong></p>
<ul>
<li><em>Check <a href="https://pypi.python.org/pypi/savReaderWriter/" rel="nofollow">https://pypi.python.org/pypi/savReaderWriter/</a> for the latest version (including the libraries!)</em></li>
<li>Requires libspssdio.so.1 (LINUX) or libspssdio.dylib (MAC) or spssio32.dll (WINDOWS) plus associated libaries, 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>It is recommended to download the v21 I/O files (required for writing zlib (.zsav) compressed files)</li>
<li>December 2012 (complete rewrite):</li>
<li>Added support for slicing, indexing, array slicing + other special methods</li>
<li>Added support for writing spss date fields</li>
<li>Added support for almost all meta data (missing values, sets, roles, etc.)</li>
<li>Added support for 64 bit Windows (tested with Win7) and other OSs
(z/Linux, Solaris, HP Linux, IBM AIX (untested though)</li>
<li>Added support for reading and writing zlib compressed (.zsav) files</li>
<li>Removed pesky segfault error when freeing memory</li>
<li>Removed errors related to encoding</li>
<li>Changed some Reader defaults (verbose=False, returnHeader=False)</li>
<li>Renamed SavDataDictionaryReader into SavHeaderReader</li>
</ul>
<p><strong>LINUX:</strong></p>
<p><em>Installation (tested on Linux Ubuntu 10):</em></p>
<ul>
<li>additional packages/files needed are: intel-icc8-libs_8.0-1_i386.deb,libicu32_3.2-3_i386.deb, libstdc++5_3.3.6-20_i386.deb, libirc.so.</li>
<li>Run the following commands in your terminal: sudo apt-get install intel-icc8-libs; sudo apt-get install libicu32; sudo apt-get install libstdc++5.</li>
<li>Then convert libirc.a (static) to libirc.so (dynamic), save in same location as libspssdio.so.1:
ar vx intel-icc8-libs_8.0-1_i386.deb; tar -xzvf data.tar.gz ./usr/lib/libirc.a; ar -x libirc.a.</li>
</ul>
<p><em>Calling the program:</em></p>
<ul>
<li>In the TERMINAL type: export LD_LIBRARY_PATH=/path/of/additional/sofiles; python /some/path/wrapperToProgram.py. You may also add ld_library_path to .bashrc</li>
<li>The wrapper starts with "from SavReaderWriter import *", followed by e.g. stuff from the if __name__ == '__main__' section</li>
</ul>
<p><strong>MAC OS:</strong></p>
<ul>
<li>you must put all the dylib files that come with the IBM
SPSS_Statistics_InputOutput_Modules_* package in the macos
directory somewhere that OS X can find them</li>
<li>one simple way to accomplish this is to copy them to /usr/lib</li>
</ul>
<p><strong>WINDOWS:</strong></p>
<ul>
<li>You can also find this dll in the installation directory of SPSS (although SPSS is _not_ needed!)</li>
<li>The .dll should be saved in the same location as this program.</li>
</ul>
<p><strong>USAGE:</strong>
See docstrings + __main__ section</p>
List of datasets in SPSS (Python)
2011-10-27T06:12:13-07:00Petr Zizkahttp://code.activestate.com/recipes/users/4179733/http://code.activestate.com/recipes/577925-list-of-datasets-in-spss/
<p style="color: grey">
Python
recipe 577925
by <a href="/recipes/users/4179733/">Petr Zizka</a>
(<a href="/recipes/tags/dataset/">dataset</a>, <a href="/recipes/tags/spss/">spss</a>).
</p>
<p>Return list with opened datasets</p>
Python 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>