Reading Data from a Database

Data from database sources are easily imported using the Database Wizard. Any database that uses ODBC (Open Database Connectivity) drivers can be read directly after the drivers are installed. ODBC drivers for many database formats are supplied on the installation CD. Additional drivers can be obtained from third-party vendors. One of the most common database applications, Microsoft Access, is discussed in this example.

Note: This example is specific to Microsoft Windows and requires an ODBC driver for Access. The Microsoft Access ODBC driver only works with the 32-bit version of IBM® SPSS® Statistics. The steps are similar on other platforms but may require a third-party ODBC driver for Access.

  1. From the menus choose:

    File > Open Database > New Query...

    Figure 1. Database Wizard Welcome dialog box
    The Welcome panel of the Database Wizard. MS Access Database is selected from the list of available data sources.
  2. Select MS Access Database from the list of data sources and click Next.

    Note: Depending on your installation, you may also see a list of OLEDB data sources on the left side of the wizard (Windows operating systems only), but this example uses the list of ODBC data sources displayed on the right side.

  3. Click Browse to navigate to the Access database file that you want to open.
  4. Open demo.mdb. See the topic Sample Files for more information.
  5. Click OK in the login dialog box.

    In the next step, you can specify the tables and variables that you want to import.

    Figure 2. Select Data step
    The Select Data dialog box with all fields selected for import.
  6. Drag the entire demo table to the Retrieve Fields In This Order list.
  7. Click Next.

    In the next step, you can select which records (cases) to import.

    If you do not want to import all cases, you can import a subset of cases (for example, males older than 30), or you can import a random sample of cases from the data source. For large data sources, you may want to limit the number of cases to a small, representative sample to reduce the processing time.

  8. Click Next to continue.

    Field names are used to create variable names. If necessary, the names are converted to valid variable names. The original field names are preserved as variable labels. You can also change the variable names before importing the database.

    Figure 3. Define Variables step
    The Define Variables step lists all of the variables selected to be imported. The Recode to Numeric cell for the Gender variable is selected.
  9. Click the Recode to Numeric cell in the Gender field. This option converts string variables to integer variables and retains the original value as the value label for the new variable.
  10. Click Next to continue.

    The SQL statement created from your selections in the Database Wizard appears in the Results step. This statement can be executed now or saved to a file for later use.

  11. Click Finish to import the data.

All of the data in the Access database that you selected to import are now available in the Data Editor.

Next