The two greatest strengths of IBM SPSS Statistics software are its drop-down
menus to simplify data analysis, and its capabilities with data handling. SPSS is
excellent for data cleaning and structuring. We're going to dive deeper
into how to sort your data as part of data cleaning.
Before you can analyze the data, you need to clean and organize the data.
To understand your data, you will very often want to sort a particular variable in
ascending or descending order. In fact, some procedures in SPSS require
you to sort data before you can use those procedures. There are two ways in
which you may want to sort data. The most common is to Sort Cases: known as a row
sort. But there may be times that you want to Sort Variables, which is known as
a column sort. When you sort data, all of the data in the data set will be sorted
based on a single variable, but the information in each case will stay
together. For example, we have three people, each with a different measure for
age, height, and income. If we sort the income variable from smallest to largest,
each person's data from the other variables stays with them. So here's how
sorting works: when we sort ascending by age, the youngest person is sorted to the
top of the data and the ages get larger (or ascend) as we move through the data.
If our data are words, then sort ascending will place them in alphabetical order.
We can also sort descending, so that the largest numbers stay on top and descend
through the column of data. For this example, we are using the demo.sav
data set that comes with SPSS. To find out how to open this data set, check the
links in the description. And I should warn you about sorting cases: that it is
not possible to un-sort the data. Once they have been sorted, you cannot return
the data to their original order. So if you want to preserve the original order
of the data, be sure that you create a unique identifier to number the cases first.
If you need to add a unique identifying number to your cases, go to Transform ->
-> Compute Variable. We will call our new target identity variable "ID". For the
numeric expression, begin by clicking on the function group All. You want this
function ($Casenum). Drag that into the numeric expression formula window and click OK.
In data view, we can see our new case numbers. If you ever sort your data set
using some other variable, you can use this new case number to return your data
to its original order.
The quickest way to sort cases in SPSS is in data view. Right-click...
(or control-click on Mac) and select Sort Ascending (or sort descending). If you ever
change your mind and you want to go back to the original order, right-click on the
ID variable - the new one that we just created - and choose Sort Ascending.
SPSS considers missing values to be the smallest value, so missing values will
appear first if you sort in ascending order, and will appear last if you sort
in descending order. You can also sort cases using the drop down menu. Go to
Data -> Sort Cases. The sort cases dialog box is displayed. Move Age in Years
variable to the Sort by: list and then click OK. Sorting by one variable is nice,
but you can also sort by one variable within a second variable. Use the dialog
recall button to bring back the sort cases dialog box. We are already sorting
by age, but we can add the household income in thousands category and click OK.
When you sort by multiple variables, SPSS
sorts the second within each level of the first. So we are sorting income
categories within ages, and that is not particularly useful. Whenever your
results do not look as expected, it's usually easy to fix. Use the dialog
recall button to bring back the Sort Cases dialog box. Drag income category
above age. Click OK. Now SPSS sorts age within each category
of income, starting with the smallest category. But what if you want to have
the largest category on top? Easy to do. Use the dialog recall button to bring
back the Sort Cases dialog box. We are sorting the age variable ascending, but
we can sort the income category descending, so that the larger incomes
are on top. Click OK. The data are sorted by income category in descending order,
and are then sorted by age in ascending order. You can save the sorted data as
their own dataset using the "Save file with sorted data" checkbox. Then click
File to specify a name and a location for the new dataset file. Although less
common than sorting cases, you can also sort variables. When you sort variables,
you can rearrange them in variable view, which also rearranges them in data view.
Select Data -> Sort Variables. Select the attributes that you want to use for
sorting. We will sort by name first. Because your variable names must start
with a letter, this technique would alphabetize them. We can select whether
we want that sorting to be ascending (alphabetical) or descending (reverse
alphabetical). But you can also sort variables based on any of these other
attributes, or by a custom attribute. For example, you could sort variables by
number of decimals, or alphabetically by labels.
When you're finished, click OK. Your variables are sorted in ascending order
according to their names, alphabetically. You will probably not do this very often,
but knowing how to sort variables is most beneficial when you have a large
data set, especially one in which you are not familiar with all of the available
variables.
you