Download SAS 9.1 SQL Procedure: User's Guide
Transcript
Retrieving Data from a Single Table Output 2.43 4 Grouping by Multiple Columns 47 Grouping without Aggregate Functions High and Low Temperatures City Country AvgHigh AvgLow ------------------------------------------------------Algiers Algeria 90 45 Buenos Aires Argentina 87 48 Sydney Australia 79 44 Vienna Austria 76 28 Nassau Bahamas 88 65 Hamilton Bermuda 85 59 Sao Paulo Brazil 81 53 Rio de Janeiro Brazil 85 64 Quebec Canada 76 5 Montreal Canada 77 8 Toronto Canada 80 17 Beijing China 86 17 Output 2.44 Grouping without Aggregate Functions (Partial Log) WARNING: A GROUP BY clause has been transformed into an ORDER BY clause because neither the SELECT clause nor the optional HAVING clause of the associated table-expression referenced a summary function. Grouping by Multiple Columns To group by multiple columns, separate the column names with commas within the GROUP BY clause. You can use aggregate functions with any of the columns that you select. The following example groups by both Location and Type, producing total square miles for the deserts and lakes in each location in the SQL.FEATURES table: proc sql; title ’Total Square Miles of Deserts and Lakes’; select Location, Type, sum(Area) as TotalArea format=comma16. from sql.features where type in (’Desert’, ’Lake’) group by Location, Type;