Subsetting Groups of Data with the HAVING Condition


The HAVING condition specifies the condition(s) that each group must satisfy in order to be included in the query output. You can use a HAVING condition to subset grouped data by using HAVING in the same query with a GROUPBY and a summary function.

Which divisions in the previous example have a minimum employee education level that is greater than 15 years ? To find out, select SAMPLE.EMPINFO and add it to the Selected Tables list. Select OK .

In the SQL QUERY COLUMNS window, select DIVISION and add it to the Selected Columns list. Remove duplicate values by selecting
View Distinct

HAVING EXPRESSION Window

To create a condition that each output group must satisfy, select
View Having Condition for Group
to display the HAVING EXPRESSION window.

click to expand

Select Summary Functions . Select MIN from the list of summary functions.

Select Education level from the Available Columns list.

Select GT from the list of operators that appears.

Select <CONSTANT enter value> from the Available Columns list. The Numeric Values dialog box appears.

click to expand

Type 15 in the Numeric field and select OK .

In the HAVING EXPRESSION window, select OK to return to the SQL QUERY COLUMNS window.

Viewing the Results of the HAVING Condition

Select
View Group(s) for Summary Functions
to display the GROUP BY COLUMNS window.

click to expand

Select DIVISION from the Available Columns list and add it to the Group By Columns list.

Select OK .

Select
Tools Run Query Run Immediate
to display the divisions whose minimum employee education level is greater than 15.

click to expand

In the SQL QUERY COLUMNS window, select
Tools Reset
to reset the query and return to the SQL QUERY TABLES window. Select OK from the dialog box that appears.




SAS 9.1 SQL Query Window. Users Guide
SAS 9.1 SQL Query Window: Users Guide
ISBN: 1590472098
EAN: 2147483647
Year: 2004
Pages: 54
Authors: SAS Institute

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net