A little announcement. A lot to explore.

Happy learning!

Explore lessons, including SAS & R programs and practice data.

Search lessons

Type at least 3 characters to see matching lessons.

Open SAS ↗Open R ↗
← SASnRLast dot concept

Introduction

  • The natural counterpart to "first of each group" is "last of each group" — the last visit per subject, the latest lab per test, the oldest age in each Sex.
  • In SAS, once a dataset is sorted by the grouping variable, the automatic flag last.var is TRUE on the last row of each group.
  • Tidyverse uses group_by() + slice(n()) or slice_tail() to keep the last row within each group.
  • Base R uses !duplicated(group, fromLast = TRUE) after sorting to keep the last occurrence per group.
  • This lesson picks the subject with the highest Height within each Sex on CLASS — the mirror image of lesson 2200.
  • As always, "last" is defined by the sort order, so we sort first and then take the last row.

Last dot concept