1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
SPSS AnswerNet: Result 

Solution ID:	 	100000547	
Creating an alphabetized active file 
Description:

Q. 
I want to have the variables in my active file sorted in 
alphabetical order. 

A. 
Try this sample syntax. It uses the FLIP command to transpose 
only the first case of data. This creates a file with one 
new variable, called CASE_LBL and one case for each variable. 
CASE_LBL's contents are the original variable names. 
We sort this new file by CASE_LBL to get the alphabetic ordering 
of the variable names. Then we FLIP the file again to get the 
variables into the alphabetic order. Now create a temporary 
variable (TMP$$_X here, or you can use another name) in order 
to match this file to the original one. We use the ADD FILES 
command to match the files. It's important that we specify the 
new file first (this is specified by FILE=* in the example 
below) because the first file listed in the ADD FILES or MATCH 
FILES commands is the file which defines the dictionary of the 
resulting file. Therefore, the resulting file will have the 
variables in the order of the new file we've created. 
After the ADD FILES command, use the SELECT IF command to drop 
that single case we created with the alphabetized variable names. 
Then save the resulting file, dropping the CASE_LBL and temporary 
TMP$$_X variables. We retrieve this file to see the results. 

SAVE OUTFILE 'temp.sav'. 
SELECT IF ( $CASENUM = 1 ). 
FLIP . 
SORT CASES BY CASE_LBL . 
FLIP NEWNAMES= CASE_LBL . 
COMPUTE TMP$$_X=1. 
ADD FILES FILE=* / FILE= 'temp.sav'. 
SELECT IF MISSING(TMP$$_X) . 
SAVE OUTFILE 'alphasrt.sav' / DROP CASE_LBL TMP$$_X. 
GET FILE 'alphasrt.sav' . 
Created on: 04/29/1999