Search code examples
macrosspss

Saving a variable ordering using Syntax in SPSS


I have a database with a lot of variables where the order of the variables is important. However, I want to sort my variables by type in between so that I can fill in the missing values by type. Before ordering them by type, I would like to save the order of the variables using Syntax so that I can return to this order after I have filled in the missing values. So the question is: How do I save a variable order using Syntax in SPSS?

I have tried using the “save current (pre-sorted) variable order” checkbox with the Paste command but that did not give me the Syntax code for saving the original order but only that of sorting the variables by type. Any help would be much appreciated.


Solution

  • You can use the following command to save the original variable order in a macro:

    SPSSINC SELECT VARIABLES MACRONAME="!origlist" VARIABLES=all /options order=file.
    

    After running this you can go ahead and change the order in the data. When you want to go back to the original order you can use this:

    add files /file=* /keep=!origlist .