How are numeric and string variables determined in SPSS?
Question: So I found this page that explains the different types of variables very well:
<http://www.spss-tutorials.com/spss-variable-types-and-formats/>

I would like to know though, how numeric and string types are differentiated
when I export my data? Are numeric and string mapped to any code?

I would like to parse SPSS data in Python.


Answer: If you take note of the print output generated from the code below, you'll
notice that string variables are "exported" to strings (not surprisingly) and
numeric variables are converted/exported to floats.

Date variables however are also converted to floats, with the date represented
as the number of seconds that have elapsed since October 14, 1582 - this is
the manner in which SPSS stores date variables but within SPSS there are then
[various
formats](http://www-01.ibm.com/support/knowledgecenter/SSLVMB_21.0.0/com.ibm.spss.statistics.help/syn_date_and_time_date_time_formats.htm)
that the date variable can be set to be displayed as (the float value stored
internally of course remains the same).

**Input file variable formats:**

![enter image description here](http://i.stack.imgur.com/kb256.png)

**Input file data view:**

![enter image description here](http://i.stack.imgur.com/rNC7j.png)

**Code to read SPSS data into Python and print results:**

    
    
    get file="C:\Program Files\IBM\SPSS\Statistics\23\Samples\English\Employee data.sav".
    begin program. 
    import spss, spssdata 
    allfiles = spssdata.Spssdata().fetchall() 
    print "\n".join([str(i) for i in allfiles])
    end program.
    

**Output:**

    
    
    namedTuple(1.0, u'm  ', 11654150400.0, 15.0, 3.0, 57000.0, 27000.0, 98.0, 144.0, 0.0)
    namedTuple(2.0, u'm  ', 11852956800.0, 16.0, 1.0, 40200.0, 18750.0, 98.0, 36.0, 0.0)
    namedTuple(3.0, u'f  ', 10943337600.0, 12.0, 1.0, 21450.0, 12000.0, 98.0, 381.0, 0.0)
    namedTuple(4.0, u'f  ', 11502518400.0, 8.0, 1.0, 21900.0, 13200.0, 98.0, 190.0, 0.0)
    namedTuple(5.0, u'm  ', 11749363200.0, 15.0, 1.0, 45000.0, 21000.0, 98.0, 138.0, 0.0)
    namedTuple(6.0, u'm  ', 11860819200.0, 15.0, 1.0, 32100.0, 13500.0, 98.0, 67.0, 0.0)
    namedTuple(7.0, u'm  ', 11787552000.0, 15.0, 1.0, 36000.0, 18750.0, 98.0, 114.0, 0.0)
    namedTuple(8.0, u'f  ', 12103948800.0, 12.0, 1.0, 21900.0, 9750.0, 98.0, 0.0, 0.0)
    namedTuple(9.0, u'f  ', 11463897600.0, 15.0, 1.0, 27900.0, 12750.0, 98.0, 115.0, 0.0)
    namedTuple(10.0, u'f  ', 11465712000.0, 12.0, 1.0, 24000.0, 13500.0, 98.0, 244.0, 0.0)
    namedTuple(11.0, u'f  ', 11591424000.0, 16.0, 1.0, 30300.0, 16500.0, 98.0, 143.0, 0.0)
    namedTuple(12.0, u'm  ', 12094012800.0, 8.0, 1.0, 28350.0, 12000.0, 98.0, 26.0, 1.0)
    namedTuple(13.0, u'm  ', 11920867200.0, 15.0, 1.0, 27750.0, 14250.0, 98.0, 34.0, 1.0)
    namedTuple(14.0, u'f  ', 11561529600.0, 15.0, 1.0, 35100.0, 16800.0, 98.0, 137.0, 1.0)
    namedTuple(15.0, u'm  ', 11987654400.0, 12.0, 1.0, 27300.0, 13500.0, 97.0, 66.0, 0.0)
    ...
    ...
    

