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 ↗
← SASnRSorting observations

Introduction

  • Arranging rows into a meaningful order is a common first step before any downstream summary or merge.
  • Typical reasons: sort by subject and visit, sort descending by date, or order a frequency output by count.
  • SAS uses proc sort with a by statement; tidyverse uses arrange() from dplyr; base R uses order() on the data frame.
  • This lesson sorts CLASS by Age ascending, then Height descending, so we can compare the three syntaxes side by side.
  • After running, the first row should be the youngest subject; within ties on Age, the taller subject should come first.

Sorting observations