Learn R Programming

SASxport (version 1.7.0)

makeSASNames: Create valid and unique SAS names from a character vector.

Description

Create valid and unique SAS names from a character vector.

Usage

makeSASNames(names, nchar = 8, maxPasses = 10, quiet=FALSE)

Arguments

names

character vector of candidate names

nchar

maximum number of characters

maxPasses

maximum number of iterations to resolve truncation-related name duplication.

quiet

Logical indicating whether to generate warning messages when names are truncated or made unique.

Value

character vector of unique names valid in SAS.

Details

This function creates valid SAS names from a list of R object or column names, properly handling case conversion (all converted to upper-case), length restrictions (8 characters), and making duplicate names unique. This is not as obvious as it appears, since the process of shortening names can cause duplicates, and adding digits to the end of names to make them unique can make them too long, so a few iterations may be required to ensure valid and unique names.

See Also

make.names

Examples

Run this code
# NOT RUN {
  ## Simple example: no duplicates or more than 8 characters
  makeSASNames( c("height","weight","age","gender"))

  ## Resolve duplicates
  makeSASNames( c("a","a","b","b","b","c") )

  ## Truncate long names
  makeSASNames( c("alphabetic", "numeric", "alphanumeric", "whitespace"))

  ## Truncate and make unique
  makeSASNames( rep( c("aaaaaaaaaaa","bbbbbbbbbb"), each=3) )

  ## Now do it quietly!
  makeSASNames( rep( c("aaaaaaaaaaa","bbbbbbbbbb"), each=3), quiet=TRUE)
# }

Run the code above in your browser using DataLab