FROM Clause

Specifies source tables or views.

See: Creating a Table and Inserting Data into It
Joining Two Tables
Joining Three Tables
Querying an In-Line View


FROM from-list

Required Arguments


specifies a temporary, alternate name for a table, view, or in-line view that is specified in the FROM clause.


names the column that appears in the output. The column names that you specify are matched by position to the columns in the output.


is one of the following:

table-name <<AS>alias>

names a single PROC SQL table. table-name can be a one-level name, a two-level libref.table name, or a physical pathname that is enclosed in single quotation marks.

view-name <<AS>alias>

names a single SAS view. view-name can be a one-level name, a two-level libref.view name, or a physical pathname that is enclosed in single quotation marks.


specifies a join. See joined-table.

(query-expression) <<AS>alias> <(column<, ...column>)>

specifies an in-line view. See query-expression.


specifies a DBMS table. See CONNECTION TO.

Note: With table-name and view-name, you can use data set options by placing them in parentheses immediately after table-name or view-name. For more information, see Using SAS Data Set Options with PROC SQL.


Table Aliases

A table alias is a temporary, alternate name for a table that is specified in the FROM clause. Table aliases are prefixed to column names to distinguish between columns that are common to multiple tables. Column names in reflexive joins (joining a table with itself) must be prefixed with a table alias in order to distinguish which copy of the table the column comes from. Column names in other types of joins must be prefixed with table aliases or table names unless the column names are unique to those tables.
The optional keyword AS is often used to distinguish a table alias from other table names.

In-Line Views

The FROM clause can itself contain a query expression that takes an optional table alias. This type of nested query expression is called an in-line view. An in-line view is any query expression that would be valid in a CREATE VIEW statement. PROC SQL can support many levels of nesting, but it is limited to 256 tables in any one query. The 256-table limit includes underlying tables that can contribute to views that are specified in the FROM clause.
An in-line view saves you a programming step. Rather than creating a view and referring to it in another query, you can specify the view in-line in the FROM clause.
Characteristics of in-line views include the following:
  • An in-line view is not assigned a permanent name, although it can take an alias.
  • An in-line view can be referred to only in the query in which it is defined. It cannot be referenced in another query.
  • You cannot use an ORDER BY clause in an in-line view.
  • The names of columns in an in-line view can be assigned in the object-item list of that view or with a list of names enclosed in parentheses following the alias. This syntax can be useful for renaming columns. See Querying an In-Line View for an example.
  • In order to visually separate an in-line view from the rest of the query, you can enclose the in-line view in any number of pairs of parentheses. Note that if you specify an alias for the in-line view, the alias specification must appear outside the outermost pair of parentheses for that in-line view.