29.12.2013 Views

Base SAS 9.1.3 Procedures Guide - Acsu Buffalo

Base SAS 9.1.3 Procedures Guide - Acsu Buffalo

Base SAS 9.1.3 Procedures Guide - Acsu Buffalo

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

1118 sql-expression 4 Chapter 45<br />

subquery returns no rows, then the result of an ALL comparison is true for each row of<br />

the outer query.<br />

If ANY is specified, then the comparison is true if it is true for any one of the values<br />

that are returned by the subquery. If a subquery returns no rows, then the result of an<br />

ANY comparison is false for each row of the outer query.<br />

The following example selects all those in PROCLIB.PAYROLL who earn more than<br />

the highest paid ME3:<br />

options ls=64 nodate nonumber ;<br />

proc sql;<br />

title ‘‘Employees who Earn More than’’;<br />

title2 ‘‘All ME’s’’;<br />

select *<br />

from proclib.payroll<br />

where salary > all (select salary<br />

from proclib.payroll<br />

where jobcode=’ME3’);<br />

Employees who Earn More than<br />

All ME’s<br />

Id<br />

Number Gender Jobcode Salary Birth Hired<br />

---------------------------------------------------<br />

1333 M PT2 88606 30MAR61 10FEB81<br />

1739 M PT1 66517 25DEC64 27JAN91<br />

1428 F PT1 68767 04APR60 16NOV91<br />

1404 M PT2 91376 24FEB53 01JAN80<br />

1935 F NA2 51081 28MAR54 16OCT81<br />

1905 M PT1 65111 16APR72 29MAY92<br />

1407 M PT1 68096 23MAR69 18MAR90<br />

1410 M PT2 84685 03MAY67 07NOV86<br />

1439 F PT1 70736 06MAR64 10SEP90<br />

1545 M PT1 66130 12AUG59 29MAY90<br />

1106 M PT2 89632 06NOV57 16AUG84<br />

1442 F PT2 84536 05SEP66 12APR88<br />

1417 M NA2 52270 27JUN64 07MAR89<br />

1478 M PT2 84203 09AUG59 24OCT90<br />

1556 M PT1 71349 22JUN64 11DEC91<br />

1352 M NA2 53798 02DEC60 16OCT86<br />

1890 M PT2 91908 20JUL51 25NOV79<br />

1107 M PT2 89977 09JUN54 10FEB79<br />

1830 F PT2 84471 27MAY57 29JAN83<br />

1928 M PT2 89858 16SEP54 13JUL90<br />

1076 M PT1 66558 14OCT55 03OCT91<br />

Note: See the first item in “Subqueries and Efficiency” on page 1119 for a note<br />

about efficiency when using ALL. 4<br />

In order to visually separate a subquery from the rest of the query, you can enclose<br />

the subquery in any number of pairs of parentheses.<br />

Correlated Subqueries<br />

In a correlated subquery, the WHERE expression in a subquery refers to values in a<br />

table in the outer query. The correlated subquery is evaluated for each row in the outer

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!