SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Performing Queries Using SQL
Writing a PROC SQL Step


To create a query, you must first reference the library where your table is stored. Then you write a basic PROC SQL step to query your table.


General form, basic PROC SQL step:
PROC SQL;
     SELECT
column-1<, . . . column-n,>
         FROM table-1 | view-1<, . . . table-n | view-n>
         <WHERE expression>
         <ORDER BY column-1<,  . . . column-n,>>;

where

  • PROC SQL invokes the SQL procedure
  • SELECT specifies the columns to be selected
  • FROM specifies the table to be queried
  • WHERE subsets the data based on a condition
  • ORDER BY sorts rows by the values of specific columns.
NOTE: Unlike other procedures, the order of clauses within a SQL SELECT statement does matter.


The SELECT Statement

The SELECT statement retrieves and displays data. It is made up of clauses, each beginning with a keyword and followed by one or more components. The SELECT statement in the sample code below contains four clauses: a SELECT clause, a FROM clause, a WHERE clause, and an ORDER BY clause. The end of the statement is indicated by the semicolon.

     proc sql;
      |-select id,lastname,netpay,grosspay,
      |         grosspay*.06 as bonus
      |----from emplib.payroll
      |----where netpay>25000
      |----order by lastname;
                         ^

back||next


Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement