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 ↗
← SASnRTranspose data - long to wide

Introduction

  • Clinical data often arrives in long shape — one row per subject per test — but reports and downstream tools usually want wide shape with one row per subject and one column per test.
  • SAS uses proc transpose with a by, var, and id statement to pivot the data.
  • Tidyverse uses pivot_wider() from tidyr, specifying the id, names, and values columns.
  • Base R uses reshape() with direction = "wide".
  • This lesson pivots a LONG dataset of lab results (usubjid, lbtestcd, lbstresn) into a WIDE dataset with one column per lab test.
  • After running, the WIDE dataset should have one row per usubjid and one column per lab test code — HGB, ALT, and AST in this sample.

Transpose data - long to wide