logo Getting Started with SAS Main menuGlossaryBackNext
    

Overview

If you read Query data, you saw ways to query a single table using PROC SQL. However, you often need data from separate tables. When you specify multiple tables, views, or query-expressions in the FROM clause, PROC SQL processes them to form one table. The resulting table contains data from each contributing table. These queries are referred to as joins.

Conceptually, when you specify two tables, PROC SQL matches each row of table A with all the rows of table B to produce an internal or intermediate table known as the Cartesian product. The Cartesian product of large tables can be huge, so typically you want to subset data by declaring the join type. There are two types of joins:

  • Inner joins return a result table for all the rows in a table that have one or more matching rows in the other table or tables.

    Inner join

  • Outer joins are inner joins that are augmented with rows that did not match with any row from the other table in the join. There are three kinds of outer joins: left, right, and full.

    Left join
    Right join
    Full join
    Left join
    Right join
    Full join

This task focuses on joining tables. For details on querying single tables, see Query data.



Point-and-Click Method

You can join tables using a point-and-click interface.

  1. In SAS, click Toolsthen Query.
  2. Use the SQL Query windows to perform joins.

You can view and save the PROC SQL code that the SQL Query window generates.



Main menuGlossaryBackNext