In this post, we will see what are 'by groups' in SAS and how SAS identifies a 'by group'.
Let us take the example data below, which shows some basic information of some students of a class.
Name | Sex | Age | Height | Weight |
Alice | F | 13 | 56.5 | 84 |
Barbara | F | 13 | 65.3 | 98 |
James | M | 12 | 57.3 | 83 |
Jane | F | 12 | 59.8 | 84.5 |
Jeffrey | M | 13 | 62.5 | 84 |
John | M | 12 | 59 | 99.5 |
Joyce | F | 11 | 51.3 | 50.5 |
Louise | F | 12 | 56.3 | 77 |
Robert | M | 12 | 64.8 | 128 |
Thomas | M | 11 | 57.5 | 85 |
SAS identifies a 'group' based on the unique value combinations of one or more variables of interest.
When we are interested in only one variable, number of groups will be equivalent to the number of unique values in that variable.
For example, if we are interested in grouping data based on Sex variable, the number of groups will be 2, one for 'F' and second for 'M'.
Name | Sex | Age | Height | Weight |
Alice | F | 13 | 56.5 | 84 |
Barbara | F | 13 | 65.3 | 98 |
James | M | 12 | 57.3 | 83 |
Jane | F | 12 | 59.8 | 84.5 |
Jeffrey | M | 13 | 62.5 | 84 |
John | M | 12 | 59 | 99.5 |
Joyce | F | 11 | 51.3 | 50.5 |
Louise | F | 12 | 56.3 | 77 |
Robert | M | 12 | 64.8 | 128 |
Thomas | M | 11 | 57.5 | 85 |
For example, if we are interested in grouping data based on Age variable, the number of groups will be 3, one for '11', second for '12', and third for '13'.
Name | Sex | Age | Height | Weight |
Alice | F | 13 | 56.5 | 84 |
Barbara | F | 13 | 65.3 | 98 |
James | M | 12 | 57.3 | 83 |
Jane | F | 12 | 59.8 | 84.5 |
Jeffrey | M | 13 | 62.5 | 84 |
John | M | 12 | 59 | 99.5 |
Joyce | F | 11 | 51.3 | 50.5 |
Louise | F | 12 | 56.3 | 77 |
Robert | M | 12 | 64.8 | 128 |
Thomas | M | 11 | 57.5 | 85 |
When we are interested in more than one variable, number of groups will be equivalent to the number of unique combinations in the list of variables.
If we are interested in grouping the data based on Sex and Age variables together, the number of groups will be 6. Ages 11, 12 and 13 for F and M.
Sex | Age |
F | 13 |
M | 12 |
F | 12 |
M | 13 |
F | 11 |
M | 11 |
Name | Sex | Age | Height | Weight |
Alice | F | 13 | 56.5 | 84 |
Barbara | F | 13 | 65.3 | 98 |
James | M | 12 | 57.3 | 83 |
Jane | F | 12 | 59.8 | 84.5 |
Jeffrey | M | 13 | 62.5 | 84 |
John | M | 12 | 59 | 99.5 |
Joyce | F | 11 | 51.3 | 50.5 |
Louise | F | 12 | 56.3 | 77 |
Robert | M | 12 | 64.8 | 128 |
Thomas | M | 11 | 57.5 | 85 |