When handling data in IBM SPSS Statistics software, it is very useful to
have an identification number - or ID variable - for each case. But what should you do when
you do not have an ID variable? We are going to dive deeper into how to add a
unique identifier in SPSS that will consecutively number each of your
participants.
I recommend always having some form of identifier for each of the cases in your
data set. This can be an identifier that came with each individual, such as a
medical records number, or it can simply be a random number. As long as every case
has a different number, then you have a unique identifier. When I'm working in
Excel, adding an ID number is easy. I always do this before I import my data
into SPSS, and I start by creating a new column. In the first row, I type 1 and
then 2 and 3, so that Excel knows the pattern that I'm looking for.
I select the range of cells and double click on that little handle to fill in
the rest of the numbers. If I wanted my identifier to always have at least three
digit numbers, I would type 101, 102, 103, and then
again double click to fill in the rest. How can you create a unique identifier
variable that consecutively numbers each case in an SPSS data set?
Here I have imported my fictitious data into SPSS, or perhaps I've been given a
data set, but in either case I still do not have a unique identifier.
Let's create one. Go to Transform -> Compute Variable. I am going to call my new
variable "ID", short for "identifier." I could call it "code" or "identification" or some
other name, if I chose. I like to label my variables as much as possible, so click
on Type & Label and we will label this as a "Random identification number."
It is a Numeric type. Click Continue. We will be using the built-in functions for this
unique identifier variable. The function is located in the Miscellaneous list, but
you can find it even more quickly by clicking on "All". The function is called
"$Casenum" and it's right at the top. Whenever you use a function, you
see the description in this box, telling you what the function does, and any
arguments that are necessary to use it. In this case, all we need is the function
itself. You can click and drag the function, but it's even faster to double
click the function to move it into the numeric expressions box. Now click OK.
In Data View, we see this ID variable and the consecutively numbered cases. Great!
But what if I want my case numbers to have three digits? In that case, I will
use my function in a formula. Use the Dialog Recall box to return to Compute
Variable. The previous function is still there. I can add 100 to all of my case
numbers, so that they will begin at 101.
If you would like to do this technique using syntax, here is the SPSS code.
Compute is the command. Name the variable ID = $CASENUM.
FORMAT the ID variable as "F" which means that it is numeric, a width of 8, and 0
decimals, period. EXECUTE runs the command. To make the cases start at 101, and add
a variable label, I would change the syntax. This time COMPUTE the variable ID2
and use the formula 100+$CASENUM. Now the ID variables will begin at 101.
This sets the format of my new ID variable to be numeric, with a width of 8,
and 0 decimals. I can set the variable LABEL for ID2 as "Random identification
number", and EXECUTE runs the command. If I had left the variable name as "ID" - without
the 2 - it would have overwritten the existing ID number with my new set of ID
numbers.