Search code examples
pythonexcellistspss

SPSS Python writing variable list to excel


Is it possible to write, from SPSS, (using Python), into a newly created Excel file, the variable list and variable labels?


Solution

  • Yes, lookup DISPLAY DICTIONARY and/or CODEBOOK. It would then be a case of exporting these outputs (from SPSS's output viewer) to Excel (OUTPUT EXPORT command).

    If you needed something more customized then you can either capture the output via OMS and do manipulations as you please (and then export to Excel) or you can use python APIS directly to retrieve variable, value labels and then write results to Excel (using any Python/Excel library of your choice such as xlrd or xlsxwriter, to name a couple).

    The latter requires much more programming knowledge whereas the former can all be done with native SPSS syntax.

    I have done something similar (producing a customized data dictionary) taking the Python programming approach and found this module written by an unknown author very useful as a basis.

    (Assuming you meant an automated way of achieving this else you could just copy and past the column of variable names and labels to Excel! Value labels can't be done similarly though for obvious reasons).