*Copyright @ www.mycsg.in;


GROUP BY with aggregate functions and HAVING in PROC SQL

What does GROUP BY do

Create sample data

Basic GROUP BY - count and sum per group

Count rows per department

Sum and average amount per department

Group by multiple columns - department and region

HAVING - filter groups after aggregation

Why WHERE cannot be used to filter group totals

Use HAVING to keep only departments above a total threshold

Combine WHERE and HAVING in the same query

MIN and MAX within groups

Key points to remember