Add Variables

Add Variables merges the active dataset with another open dataset or external IBM® SPSS® Statistics data file that contains the same cases (rows) but different variables (columns). For example, you might want to merge a data file that contains pre-test results with one that contains post-test results.

  • If you are not matching cases based on the values of key variables, file order determines how cases are matched.
  • If one or more key variables are used to match cases and you indicate that the files are already sorted, the two datasets must be sorted by ascending order of the key variable(s).
  • Variable names in the second data file that duplicate variable names in the active dataset are excluded by default because Add Variables assumes that these variables contain duplicate information.

Indicate case source as variable. Indicates the source data file for each case. This variable has a value of 0 for cases from the active dataset and a value of 1 for cases from the external data file.

Excluded Variables. Variables to be excluded from the new, merged data file. By default, this list contains any variable names from the other dataset that duplicate variable names in the active dataset. Variables from the active dataset are identified with an asterisk (*). Variables from the other dataset are identified with a plus sign (+). If you want to include an excluded variable with a duplicate name in the merged file, you can rename it and add it to the list of variables to be included.

New Active Dataset. Variables to be included in the new, merged dataset. By default, all unique variable names in both datasets are included on the list.

Key Variables. You can use key variables to correctly match cases in the two files. For example, there may be an ID variable that identifies each case.

  • If one of the files is a table lookup file, you must use key variables to match cases in the two files. Key values must be unique in table lookup files. If there are multiple keys, the combination of key values must be unique.
  • The key variables must have the same names in both datasets. Use Rename to change the key variable names if they are not the same.

Non-active or active dataset is keyed table. A keyed table, or table lookup file, is a file in which data for each "case" can be applied to multiple cases in the other data file. For example, if one file contains information on individual family members (such as sex, age, education) and the other file contains overall family information (such as total income, family size, location), you can use the file of family data as a table lookup file and apply the common family data to each individual family member in the merged data file.

  1. Open at least one of the data files that you want to merge. If you have multiple datasets open, make one of the datasets that you want to merge the active dataset.
  2. From the menus choose:

    Data > Merge Files > Add Variables...

  3. Select the dataset or external IBM SPSS Statistics data file to merge with the active dataset.

To Select Key Variables

  1. Select the variables from the external file variables (+) on the Excluded Variables list.
  2. Select Match cases on key variables in sorted files.
  3. Add the variables to the Key Variables list.

The key variables must exist in both the active dataset and the other dataset.