Exporting 'variable view' data as csv

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

Posts: 1
Joined: Mon Mar 31, 2014 10:53 am

Exporting 'variable view' data as csv

Postby explodecomputer » Mon Mar 31, 2014 10:56 am

Hi all

Hopefully there is a trivial way to do this, I would like to know the syntax to read in a .sav file and then export the variable view table as a csv file. The main thing that I want is to have a plain text output that contains the variable NAME and variable LABEL for all variables. I have hundreds of files to do this on, so doing it manually by copy and paste is not really possible.

Thanks in advance for your time!
Posts: 6
Joined: Thu Nov 20, 2014 4:38 pm

Re: Exporting 'variable view' data as csv

Postby wiibtr » Mon Jan 12, 2015 4:42 pm


I know your question's been asked a long time ago, but did you get an answer? Because I'm now asking the same thing. I'd like to put into a table the list of the variables in one variable "NAME" and their label in "LABEL" in a csv or sav table.

Thank you.
Posts: 1
Joined: Wed Jun 17, 2015 8:41 am

Re: Exporting 'variable view' data as csv

Postby haya » Wed Jun 17, 2015 8:49 am

I need an answer too, please
Posts: 119
Joined: Wed May 25, 2011 7:07 am

Re: Exporting 'variable view' data as csv

Postby JonPedersen » Thu Jun 18, 2015 10:28 am

One way to do this would be to write a small python script.
Here is an example (it writes the dictionary from current dataset).

Code: Select all

import spss
import csv
with open('C:\\Users\\YOU\\somewhere\\names.csv', 'wb') as csvfile:
    writer = csv.writer(csvfile, delimiter=',',
                            quotechar='"', quoting=csv.QUOTE_MINIMAL)
    for i in xrange(varcount):
If you want more " around your strings, exchange _MINIMAL with _ALL
Posts: 28
Joined: Mon Mar 30, 2009 8:20 pm

Re: Exporting 'variable view' data as csv

Postby Erikyo » Fri Jul 03, 2015 2:51 pm

If you are not using Python, the following is not exactly what you want but it's the next best thing :

CODEBOOK var1 [n] var2 [n] var3 [n]
Posts: 100
Joined: Mon May 19, 2014 6:06 am

Re: Exporting 'variable view' data as csv

Postby RubenGeert » Sat Jul 04, 2015 8:33 am

First, "variable view" is called the dictionary in SPSS. See: http://www.spss-tutorials.com/spss-dictionary/

Second, none of the examples will work easily for many files. The best thing to do is probably have Python look up all filenames. An example is shown here: http://www.spss-tutorials.com/move-all- ... in-folder/

Note that SYSFILE INFO allows retrieving dictionary information from .sav files without opening them. You can use OMS for getting the information from the viewer into an SPSS dataset which you can save as a .csv file. Something that comes quite close to that is http://www.spss-tutorials.com/create-di ... y-dataset/.

So regarding the original question:

-Use Python for looking up all file names and looping over them. Within this loop:

-Use OMS for capturing dictionary info
-Use SYSFILE INFO for generating dictionary info
-OMSEND. launches dataset with info, perhaps add some lines here for cleaning it up
-Save as dataset as .csv file
-Close dataset
-Next .sav file

If that proves too much of a challenge, feel free to contact me, I can write out the required syntax if necessary.


Who is online

Users browsing this forum: No registered users and 1 guest