Sorting and Rearranging Variables’ Name with SPSS Syntax
Recently I came across this tricky task: sorting variable name in SPSS Data Editor. It should not be a problem with only few variables, but imagine to do it for a couple hundreds variables! OK maybe I’m not clear enough in explaining this. For example I have a data set with variable name Var001, Var003, and Var002 and I want to order it to Var001, Var002 and Var003.
After googling I found the solution listed here. The syntax command:
FLIP.
SORT CASES BY case_lbl.
FLIP NEWNAMES=case_lbl.
The first command is transposing the data file, this means that all of your variables’ name will be listed in one variable. The second command is sorting the variable. The last one transposing again to its original structure.
However this syntax turns out to be very bad solution. After the first transposing command the variables is losing its variable definition such as variable label, missing value, column etc. This thing happen because each variables turn into a variable value. After digging some more information the solution is quite simple: utilizing save command! The syntax is like so:
SAVE OUTFILE=’C:/test.sav’
/KEEP= var001 var002 var003.
These commands basically save the data set in different order. If you have a lot of variables and you want to sort it alphabetically, just sort your variable list in word processor like Openoffice.org or MS Word.
Comments
Comment from Roland
Time: December 5, 2008, 12:15 am
Yeeha, exactly what I was looking for. Thanks a lot!
- Roland
Comment from Lance
Time: June 21, 2009, 4:45 am
SPSS 17 new Improvements: – Complete datasets for more reliable analysis using multiple imputation procedure in SPSS Missing Values – Improved administrative tools to facilitate software configuration – Syntax editor update makes it simpler to generate, test and correct syntax – Better integration with Office – SPSS EZ RFM (Recency, Frequency, Monetary value) helps analysts pick out top customers – Capable of integrating third party applications, procedures, and graphics packages that are created in R – Several new algorithms, faster speed and performance
for help – http://www.usingspss.com
E-mail subscription






Comment from Idetrorce
Time: December 16, 2007, 1:03 am
very interesting, but I don’t agree with you
Idetrorce