General FAQ's

What is a keyed table?

SPSS 16.0 and later - There are two basic characteristics for a keyed table:

  1. A keyed table has to have unique cases based on the key variable(s).
  2. A keyed table doesn't contribute cases to the merged file. It contributes variables only.

A keyed table file is also called a table lookup file. And it might help if you think of a keyed table as a dictionary with definitions for words. It can be a comprehensive dictionary with definitions for all of the words, but it doesn't have to be (so the larger data file is not necessarily the keyed table file). In the dictionary, there is one entry for each word with its definition. When you merge files, you're adding definitions to all of the words that are also in the other file. Words that are in the dictionary but not in the other file are not added to the merged file.
 

How do I calculate the difference between two dates, resulting in days, months or years?

If you are using SPSS 14.0 for Windows or later, the Date/Time wizard (found under Transform -> Date/Time) can calculate the difference between two dates with results in days, months or years. In addition, the function is available within the SPSS Utilities module. Choose SPSS Utilities-> Time between days-> Calculate in days. Then choose whether or not to include bank holidays.

When using SPSS Syntax to calculate the difference between two dates, functions are used to process date values. These functions allow for flexibility while working with dates of varying formats. The following syntax examples demonstrate several ways to calculate the time between two dates.

A.   Examples of Results in Days
B.   Examples of Results in Months
C.   Examples of Results in Years

* Sample data set to demonstrate the examples.

Data List fixed/ date1 1-10 (adate) date2 11-20 (adate).
Begin Data
06/12/199705/09/2007
12/08/199705/09/2007
10/25/199705/09/2007
04/25/198705/09/2007
02/16/199705/09/2007
03/19/199805/09/2007
End Data.
EXE.

*A.   Examples of Results in Days.

*Subtract the two date values, divide by (60 seconds * 60 minutes * 24 hours).
COMPUTE days1 = (date2 - date1) / (60 * 60 * 24)  .
EXE  .
*You may also use the DATEDIFF function.
COMPUTE days2 = DATEDIFF(date2,date1,"days").
EXE.
*Or even the CTIME.DAYS function.
COMPUTE days3 = CTIME.DAYS(date2 - date1).
EXE.

*B.   Examples of Results in Months.
*Subtract the two date values, divide by (60 seconds * 60 minutes * 24 hours * 365.25 days / 12 months).
COMPUTE month1 = (date2 - date1) / (60 * 60 * 24 * 365.24 / 12)  .
EXE  .
*You may also use the DATEDIFF function.
COMPUTE month2 = DATEDIFF(date2,date1,"month").
EXE.

*C.   Examples of Result in years (Can be used to calculate the age)
*Subtract the two date values, divide by (60 seconds * 60 minutes * 24 hours * 365.25 days)
COMPUTE year1 = (date2 - date1) / (60 * 60 * 24 * 365.24) .
EXE.
*You may also use the DATEDIFF function.
COMPUTE year2 = DATEDIFF(date2,date1,"year").
EXE.
*Another way to calculate the age using the system date.
COMPUTE age = CTIME.DAYS($TIME - date1)/365.24.
EXE.
 

How do I select cases in SPSS for Windows using either syntax or the windows?

Go to Data->Select cases and select 'If condition is satisfied'. Enter a conditional statement, click Continue, and then, OK. If the condition contains a variable that is string, make sure you type single quote marks around each end of the string. The pasted syntax appears below, along with a sample data file.

DATA LIST / v1 1 (f) v2 2 (a).
BEGIN DATA
1a
1a
1b
2b
2c
2c
3d
3d
END DATA.
EXE.

*Pasted syntax for selecting on numeric variable.
USE ALL.
COMPUTE filter_$=(v1=1).
VARIABLE LABEL filter_$ 'v1=1 (FILTER)'.
VALUE LABELS filter_$ 0 'Not Selected' 1 'Selected'.
FORMAT filter_$ (f1.0).
FILTER BY filter_$.
EXECUTE .

*Pasted syntax for selecting on string variable.
USE ALL.
COMPUTE filter_$=(v2='b').
VARIABLE LABEL filter_$ "v2='b' (FILTER)".
VALUE LABELS filter_$ 0 'Not Selected' 1 'Selected'.
FORMAT filter_$ (f1.0).
FILTER BY filter_$.
EXECUTE.

Alternatively, using a SELECT command from syntax will delete unselected cases from the file.
SELECT IF (V1=1).
EXE.

The addition of a TEMPORARY command will limit the selection to the following procedure, after which the selection becomes inactive.
TEMPORARY.
SELECT IF (v1=1).
FREQ VARS=V2.
EXE.

How do I save the multiple response sets I've defined through the menus in SPSS?

The multiple response sets that are defined through dialog boxes only exist for as long as that current session of SPSS is open. When you run a multiple response frequency or crosstabs, the set is actually created within the syntax for that table, and the set only exists while that syntax is run. The menu provides a convenient graphical interface to associate variables into sets, but SPSS recreates each set every time the multiple response frequency or crosstab is run. However, if you have the Custom Tables Module, the sets that are created through those dialog boxes are saved from session to session, as long as you save the data file in which the sets were created.

If you do not have the Custom Tables module, or wish to continue using the regular Multiple Response option, the only way to "save" the multiple response set is to save the syntax that creates the multiple response table. Create the multiple response sets as you normally would, and then set up your multiple response table. Instead of clicking on OK, click on paste. The table will not run, but the syntax that will create the table will be pasted into a SPSS syntax file. For example, the following syntax creates a crosstab table of the multiple response variable called health and a variable called sex:

MULT RESPONSE
GROUPS=$health (hlth1 hlth2 hlth3 hlth4 hlth5 (1))
/VARIABLES=sex(1 2)
/TABLES=$health BY sex
/BASE=CASES.

The groups subcommand defines the multiple response set, (in this case, a multiple dichotomy set), the variables subcommand define which regular variables are to be used in the crosstab, as well as their ranges. The table subcommand creates the table, where $health is the multiple response set we created on the groups command and sex is the regular table. You can save this syntax by going to File->Save and giving the syntax file a name.

Now, let's say the next day you wanted to run another multiple response crosstab, using the same multiple response set, but with another variable, such as race. Open your dataset as usual, and then go to File->Open. Select SPSS syntax as your file type, and open up the syntax file you saved previously. You would modify the above syntax and end up with the following:

MULT RESPONSE
GROUPS=$health (hlth1 hlth2 hlth3 hlth4 hlth5 (1))
/VARIABLES=race(1 3)
/TABLES=$health BY race
/BASE=CASES.

I kept the GROUPS subcommand the same, and the same set is created again. However, I changed the variables designation to race, and changed the range to reflect the range of my race variable. Then, I replaced sex with race on the tables subcommand. Now highlight the syntax, and go to Run->Selection. In the output window, you should see a crosstab, using the same multiple response set, but with race rather than sex.

Remember, the multiple response set only lasts as long with the syntax that creates it and uses it. If you want to use the multiple response set again, the multiple response groups syntax has to be run again, and the variables and tables subcommand changed as needed. These sets will also not show up under Multiple Response->Define Sets, unless you redefine them through the menus.
 

How can I compute age using SPSS?

If you have SPSS 13.0 for Windows or later, you can use the Date/Time wizard, found under Transform -> Date/Time to calculate the difference between two dates.

Otherwise, use the following instructions.

Creating a variable that contains the age of each respondent can be done in a variety of ways depending on the information you are looking for. This solution provides two examples of how to compute an age. The first example computes the age in the number of years. The second example computes age in the number of years and days. In order for these examples to work with your own dataset, you will need to replace the variable names such as BDATE, D1 and D2 with the names of your own date variables.

The first example assumes that you want to compute the age of an individual based on today's date. First, we create a new variable called TODAY, which will hold today's date. The $TIME variable is a system variable in SPSS that keeps today's date as its value. The XDATE.DATE function converts values, in this case the value of $TIME, into a format that SPSS can recognise as a date.

COMPUTE TODAY=XDATE.DATE ($TIME)

All you will see in the Data Editor after running the first compute command is a very large number, which represents the number of seconds since the beginning of the Gregorian Calendar. We could give this variable a display format that it would make it look like an actual date, but it isn’t necessary.

Once we have our today variable, we can subtract it from our birth date. Our birthday should already be formatted as an SPSS date variable. The CTIME.DAYS function will allow us to subtract the two variables from each other and display difference as the number of days rather than the number of seconds. Then, we divide the variable by 365.25, which will then return a value that will be the number of years between today and the birthday.

COMPUTE AGE= (CTIME.DAYS (TODAY-BDATE))/365.25.

Most likely, all of the values in your age variable will have decimal values, such as 35.54, since probably most people's birthdays aren't today. If you want to have a variable that only contains the year, without the decimal points, you could then use the following commands:

COMPUTE NEWAGE=TRUNC(AGE).
FORMATS NEWAGE (F3.0).

These commands would chop off all the decimal points, leaving you with 35. If rather than truncating the value, you wanted to round, you would use the command which would give you 36. :

COMPUTE NEWAGE=RND(AGE).
FORMATS NEWAGE (F3.0).

If you wanted to be more precise and wanted to know the number of years and days since their birthday, you could use the following example:

*The data list just creates some sample data. You wouldn't use this part on your own data.
DATA LIST / bday 1-10 (adate).
BEGIN DATA
08/26/1959
11/04/1972
END DATA.

*This syntax example uses the functions as we used above, except for the new function called MOD, Using the CTIME.DATS function, you can compute the age in years between today and the BDATE value. That value is truncated as well. To get the days, we find the remainder of the age value (which gives us the number of days since the last birthday).

COMPUTE age=TRUNC(CTIME.DAYS($time-bday)/365.25).
COMPUTE days=TRUNC(MOD(CTIME.DAYS($time-bday),365.25)).
FORMATS age days (f3.0).
LIST.
 

Can you describe the recode functions in SPSS?

There are two recode functions found on the Transform menu within SPSS:
                                                                                                     

  • Recode into Different Variable

Recode into Same Variable allows you to reassign values of an existing variable. The new values will replace the old within the current variable. For example, you can recode each value of 7 in your variable to become 1. The Recode into Same Variables: Old and New Values dialog box allows you to enter in the old and new values for the variable of your choice. This change will take place within the existing variable.
 

  • Recode into Same Variable   

Using the Recode into Different Variables will create a new variable containing the new values. Recode can replace a single value in a variable, a series of values or collapse groups of values into a single value. The recode categories must be discrete. Categories that overlap will fail to recode. 
For example, the value ranges listed below would fail, as the value 3 belongs to two categories.

Old values New Values
1-3 1
3-5 2

Instead, the value of 3 should fall into one or the other category.

Old values New Values
1-3 1
4-5 2

When converting strings to numeric values please use 'Recode into Different Variables'. You are creating a new variable type and therefore must place the new values in variable with the correct format. If the values in the old string variables are numbers, please use the 'Convert numeric strings to numbers' check-box. This setting will convert the string values into numbers in the new variable. If converting alpha strings, you must identify each string and its new value. String values that are not entered will become system missing values in the new numeric variable.
 

Contact Details

(P) +27 21 702 4666
(F) +27 21 702 4333

Physical Address:

Silvermine House,
Steenberg Office Park,
Tokai,
Cape Town,
South Africa,
7945