Solution ID: 100007493 Product: SPSS Base Version: O/S: Question Type: General Operations Question Subtype: Title: Rearranging variables alphabetically in the Data Editor Description: Q. I need to rearrange my data so that my variables appear in the data editor in alphabetical order. How do I accomplish this? A. This task can be done by transposing the data file, sorting it, then transposing it again to restore its original structure, as in FLIP. SORT CASES BY case_lbl. FLIP NEWNAMES=case_lbl. The remaining case_lbl variable in the file can be dropped at this point. This process can also be done via the menus in any version of SPSS which features them. In recent versions of SPSS for Windows, for example, this procedure would accomplish the same thing: First, flip the file using the following steps: 1. Go into Data>Transpose. 2. Highlight all your variables and move them to the Variables box. 3. Click "Ok". Then, sort your file: 1. Go into Data>Sort Cases... 2. Highlight the variable "case_lbl" (this variable is created in the Transpose process) and move it to the "sort by..."box. 3. Select "Ascending". 4. Click "Ok". Finally, flip the file back: 1. Go into Data>Transpose... 2. Highlight all the variables EXCEPT "case_lbl" and move them into the "Variables" box. 3. Highlight "case_lbl" and move it into the "Name Variable" box. 4. Click "Ok". Your file is rearranged. As with the command syntax route, you may then delete the "case_lbl" variable, if you wish. It is important to note that the relatively straightforward procedures described above will be effective only for files composed strictly of numeric variables with no variable or value labels, since * any string variable in the data file will be lost in the act of transposing the file * the formats and labels of your variables will be lost as well With a few extra steps, however, the substantive content of string variables as well as variable and value labels can be preserved. Here is an annotated example of this involving a file with any number of variable and value labels and a single string variable: *This creates a numeric variable with the string variable's content as its labels. AUTORECODE VARS=stringvar /INTO numvar/PRINT. *We then save a copy of the file to preserve the data dictionary for later use. SAVE OUTFILE='format.sav'. *We can then flip the file twice, as described in the simple case above. FLIP. SORT CASES BY case_lbl. FLIP NEWNAMES=case_lbl. *Matching the file to itself allows us to drop the unneeded variables. MATCH FILES FILE=*/DROP stringvar case_lbl. *The file currently has no labels (including those that tell us what the former string values in "stringvar" were) or formatting information. We can, however, apply the dictionary from the backup version of the file to restore this. APPLY DICTIONARY FROM='format.sav'. EXE. In the above... *..."stringvar" is your string variable(s)(You'll need to specify each on the AUTORECODE command)... *..."numvar" is your newly recoded variable... *..."case_lbl" is an identifier variable created in the FLIP procedure... *... and "format" is your data file with the string variables converted to numeric ones, for purposes of reimposing the variable labels and formats. As with the simple case of numeric variables with no additional dictionary information, you may also perform this procedure through the menus, if you wish. First, recode the string variables in your file: 1. Go into Transform->Automatic Recode. 2. Specify your string variable(s) and move into the "Variable->New Name" box. 3. Enter the new names and click the "New Name" button. 4. Click "Ok". Save the resulting file. Then, flip your file: 1. Go into Data->Transpose. 2. Highlight all your variables and move them to the Variables box. 3. Click "Ok". Next, sort your file: 1. Go into Data->Sort Cases... 2. Highlight the variable "case_lbl" (this variable is created in the Transpose process) and move it to the "sort by..."box. 3. Select "Ascending". 4. Click "Ok". Then, flip the file back: 1. Go into Data->Transpose... 2. Highlight all the variables EXCEPT "case_lbl" and move them into the "Variables" box. 3. Highlight "case_lbl" and move it into the "Name Variable" box. 4. Click "Ok". Your file is rearranged. You may then delete the "case_lbl" variable and your string variables, if you wish. Finally, Go into Data->Apply Data Dictionary and choose the file you saved previously. This will restore your labels and variable formats. One final note: in SPSS for Windows, there exists an option which allows one to sort the variable source lists in alphabetical order by name (and, in later versions, by label). If your purpose in sorting variables alphabetically on the dictionary is to strictly to affect these source lists, it would be easier to just utilize this option.