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 ↗
← SASnRSort Order with Missing Values

Introduction

  • Sorting becomes trickier the moment missing values enter the picture — do NAs belong at the top, at the bottom, or should they be dropped?
  • SAS PROC SORT places missing values first in ascending order and last in descending order.
  • Tidyverse arrange() always pushes NAs to the bottom by default, regardless of sort direction, so we steer them explicitly.
  • Base R order() drops NAs by default; we can change that with the na.last argument or a small trick on missingness.
  • This lesson sorts a small dataset where two rows have a missing score, so the placement of the NAs is easy to see in each language.

Sort Order with Missing Values