Is there a syntax code to create a new variable in a specific position, that is, before or after another variable? I'm working with a dataset and I'd prefer not to drag every new variable I create from the end of the variable list to the place where I want them to be.
Thanks!
Answer by jkpeck (6118) | Jun 04 at 09:47 AM
There is no syntax for creating a variable in a specific position, but there are a few things that might help.
The SORT VARIABLES command allows you to reorder the variables according to the variable properties - name, measurement level, label, type, custom attributes, etc.
You can use the ADD FILES or MATCH FILES command to reorder the variables. For example,
MATCH FILES /FILE=* /KEEP jobcat ALL.
would put the jobcat variable first in the file. But you would need a complete variable list (or ALL). However, you can use TO, which eliminates the need to list every variable. For example,
/KEEP id to salary educ all
would place educ after salary but retain all the variables assuming that id is the first variable.
As you probably know, in dialog boxes you can sort the variable list according to name, file location, or measurement level.
Finally, it would be pretty simple to write a small bit of Python code to move a variable or set of variables to be before or after another variable.