O'Reilly logo

SAS 9.4 Language Reference, 6th Edition by SAS Institute

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

GROUPFORMAT
uses the formatted values, instead of the internal values, of the BY variables to
determine where BY-groups begin and end, and therefore how FIRST.variable and
LAST.variable are assigned. Although the GROUPFORMAT option can appear
anywhere in the BY statement, the option applies to all variables in the BY
statement.
For complete information about the BY statement, see “BY Statement” in SAS
Statements: Reference.
Understanding BY Groups
BY Groups with a Single BY Variable
The following figure represents the results of processing your data with the single BY
variable ZipCode. The input SAS data set contains street names, cities, states, and ZIP
codes that are arranged in an order that you can use with the following BY statement:
by ZipCode;
The figure shows five BY groups each containing the BY variable ZipCode. The data set
is shown with the BY variable ZipCode printed on the left for easy reading. However,
the position of the BY variable in the observations does not matter.
Figure 20.1 BY Groups for the Single BY Variable ZipCode
BY group
BY group
BY group
BY Group
BY group
St r e e t
Ri c e St
T h o ma s Av e
Su r r e y Dr
T r a d e Av e
Ne r v i a St
Co r s i c a St
F r e n c h A v e
E g r e t Dr
Do me n i c L n
Gl e e s o n P l
Ci t y
Mi a mi
Mi a mi
Mi a mi
Mi a mi
Mi a mi
Mi a mi
L a k e l a n d
L a k e l a n d
T u c s o n
T u c s o n
St a t e
F L
F L
F L
F L
F L
F L
F L
F L
AZ
AZ
Z i p Co d e
3 31 3 3
3 31 3 3
3 31 3 3
3 31 3 3
3 31 4 6
3 31 4 6
3 38 0 1
3 38 0 9
8 57 3 0
8 57 3 0
BY variable
The first BY group contains all observations with the smallest BY value, which is
33133; the second BY group contains all observations with the next smallest BY value,
which is 33146, and so on.
BY Groups with Multiple BY Variables
The following figure represents the results of processing your data with two BY
variables, State and City. This example uses the same data set as in “BY Groups with a
Single BY Variable” on page 451, and is arranged in an order that you can use with the
following BY statement:
Understanding BY Groups 451

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