The GROUP BY clause enables you to
break query results into subsets of rows. When you use the GROUP BY
clause, you use an aggregate function in the SELECT clause or a HAVING
clause to instruct PROC SQL how to group the data. For details about
aggregate functions, see
Summarizing Data. PROC SQL calculates the aggregate function separately for
each group. When you do not use an aggregate function, PROC SQL treats
the GROUP BY clause as if it were an ORDER BY clause, and any aggregate
functions are applied to the entire table.
The following query
uses the SUM function to list the total population of each continent.
The GROUP BY clause groups the countries by continent, and the ORDER
BY clause puts the continents in alphabetical order:
select Continent, sum(Population)
from sql.countries
group by Continent
order by Continent;