
Last chance! 50% off unlimited learning
Sale ends in
Create valid and unique SAS names from a character vector.
makeSASNames(names, nchar = 8, maxPasses = 10, quiet=FALSE)
character vector of candidate names
maximum number of characters
maximum number of iterations to resolve truncation-related name duplication.
Logical indicating whether to generate warning messages when names are truncated or made unique.
character vector of unique names valid in SAS.
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.
# 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