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 ↗
← SASnRConvert Between Character and Numeric Variables

Introduction

  • Type conversion between character and numeric is a constant need in clinical data — strings come in from CDISC specs, numbers come back out for analysis.
  • Two directions to know: character to numeric for analysis, numeric to character for report layout.
  • In both directions, invalid values (e.g. "ABC" in a numeric column) need to become missing rather than crashing the program.
  • SAS uses input(char, informat.) for character-to-numeric and put(num, format.) for numeric-to-character.
  • R uses as.numeric() and as.character() directly in both tidyverse and base dialects.
  • This lesson demonstrates both conversions on a mixed dataset that includes one invalid string ("ABC") so we can see how each language handles the edge case.

Convert Between Character and Numeric Variables