O'Reilly logo

Combining and Modifying SAS® Data Sets: Examples Second Edition by Michele M. Burlew

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Example 5.4 Subsetting a Table Based on the Calculated Average of a Group

Goal

Compute the average of a column for each group in a table. Select observations from each group based on the group's average.

Example Features

Featured StepPROC SQL
Featured Step Options and StatementsAVG aggregate function GROUP BY clause HAVING clause
Related TechniquePROC MEANS, CLASS, OUTPUT, and TYPES statements DATA step, match-merging by value

Input Table

Table SOYBEANS contains the soybean yield and acres of soybeans planted for 30 farms in four regions.

                 SOYBEANS


Obs    region    farmid    yield    acres 1 NW 456 33 95 2 NW 269 38 346 3 NW 295 31 59 4 NW 689 22 373 5 NW 080 30 289 6 NW 319 28 83 7 NW 703 29 114 8 SW 700 36 122 9 SW 178 28 214 10 SW 358 31 817 11 SW 045 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required