Search code examples
macrosspss

Keeping original variable order with 'select variables' command


The following code was used to generate a list of numeric variables and their maxima and minima from a datafile containing >500 variables and >2000 cases:

OMS select tables
/if commands=["descriptives"]
subtypes=["descriptive statistics"]
/DESTINATION FORMAT = SAV
OUTFILE = "C:\statyMcStatFace.sav".

SPSSINC SELECT VARIABLES MACRONAME="!nums" /PROPERTIES TYPE= NUMERIC.

DESCRIPTIVES !nums /STATISTICS=MIN MAX.

omsend.

Sadly, the variables weren't listed in the same order in the output file as they were in the original file, nor according to any discernible order I can see. For example, if you run the given code on plantar_fascitiitis.csv at

kaggle.com/rameessahlu/plantar-fasciitis

you'll find that the order of the variables in the original table is age, sex, weight... etc., while the order the variables are listed in the macro is Status, TendernessOfFoot, Alignment, Burning... etc.. Why does this happen, and is there a way for me to order the variables as they are in the original table?


Solution

  • When you are creating your numerical variables list using the select variables command, there is an option to keep the created list in the original order of the dataset. So all you have to do is use the command with this addition:

    SPSSINC SELECT VARIABLES MACRONAME="!nums" /PROPERTIES TYPE= NUMERIC /OPTIONS ORDER=FILE.