Search code examples
spss

Saving a list of variables in a file


I'd like to automate the syntax. The number of variables varies from year to year. In one year the variable state occurs four times, in the next maybe six times.
I'd like to use something like WRITE OUTFILE to store a list containing the variable names and which I can call whenever needed.


Solution

  • Not sure how you can get a few variables called "state" in the same dataset? In any case, if you want a list of the variables in your data saved as a new file, you can do this:

    dataset declare ListOfVars.
    oms /select tables /if commands=['File Information'] subtypes=['Variable Information']
      /destination format=sav outfile='ListOfVars' .
    display dictionary.
    omsend.
    dataset activate ListOfVars.
    

    The new dataset ListOfVars has the list of your variables and their labels (and some other data). Now just save the table to a new fine and keep whatever variables you need from it.