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 ↗
← SASnRSelect Distinct Values Using SQL

Introduction

  • A quick "what are the unique values?" check is one of the most common tasks in clinical programming β€” listing treatment groups, visit names, or distinct subjects in a dataset.
  • SAS uses PROC SQL with SELECT DISTINCT to retrieve unique values. R has distinct() in dplyr and unique() in base R.
  • This lesson shows how to pull distinct values from one or more columns, and how to save the result as a new dataset.
  • We use a small ADSL-like dataset with duplicate treatment-by-sex combinations to make the deduplication visible.
  • After running, we confirm that only the unique combinations remain in the output.

Select Distinct Values Using SQL