SQL Procedure

Implements the Structured Query Language for SAS.
See: Base SAS Procedures Guide

SAS SQL Procedure User's Guide

SAS SQL Query Window User's Guide

Syntax

PROC SQL <options-list>
CONNECT TO data-source-name AS <alias> <(connect-statement-arguments)> ,
<(database-connection-arguments)>
DISCONNECT FROM <data-source-name> <alias>
EXECUTE (data-source-specific-SQL-statement)
BY
<data-source-name> <alias>
SELECT column-list
FROM
CONNECTION TO data source-name
AS
<alias> <database-connection-arguments;>

Without Arguments

Use the CONNECT TO statement with the SQL procedure to query data from a data source.

Details

Return Codes

As you use the PROC SQL statements that are available in the pass-through facility, any error conditions are written to the SAS log. The pass-through facility generates return codes and messages that are available to you through these SAS macro variables:
SQLXRC
contains the data source return code that identifies the data source error.
SQLXMSG
contains descriptive information about the data source error that is generated by the data source.
The contents of the SQLXRC and SQLXMSG macro variables can be written to the SAS log using the %PUT macro. The contents are reset after each pass-through facility statement is executed.

Example: Connect to an Excel 2007 .xlsx File and Query the INVOICE Table (range) within the Excel Workbook

PROC SQL DQUOTE=ANSI;
CONNECT TO EXCEL (PATH='c:\sasdemo\sasdemo.xlsx');
SELECT * FROM CONNECTION TO EXCEL
   (SELECT * FROM invoice);
DISCONNECT FROM EXCEL;
QUIT;