Description Usage Arguments Details Value Author(s) See Also Examples
Create valid and unique SAS names from a character vector.
1 | makeSASNames(names, nchar = 8, maxPasses = 10, quiet=FALSE)
|
names |
character vector of candidate names |
nchar |
maximum number of characters |
maxPasses |
maximum number of interations to resolve truncation-related name duplication. |
quiet |
Logical indicating whether to generate warning messages when names are truncated or made unique. |
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 restructions (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.
character vector of unique names valid in SAS.
Gregory R. Warnes greg@warnes.net
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | ## 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)
|
[1] "HEIGHT" "WEIGHT" "AGE" "GENDER"
[1] "A" "A.1" "B" "B.1" "B.2" "C"
Warning message:
In makeSASNames(c("a", "a", "b", "b", "b", "c")) :
Made 3 duplicate names unique.
[1] "ALPHABET" "NUMERIC" "ALPHANUM" "WHITESPA"
Warning message:
In makeSASNames(c("alphabetic", "numeric", "alphanumeric", "whitespace")) :
Truncated 3 long names to 8 characters.
[1] "AAAAAA" "AAAAAA.1" "AAAAAA.2" "BBBBBB" "BBBBBB.1" "BBBBBB.2"
Warning messages:
1: In makeSASNames(rep(c("aaaaaaaaaaa", "bbbbbbbbbb"), each = 3)) :
Truncated 6 long names to 8 characters.
2: In makeSASNames(rep(c("aaaaaaaaaaa", "bbbbbbbbbb"), each = 3)) :
Made 4 duplicate names unique.
[1] "AAAAAA" "AAAAAA.1" "AAAAAA.2" "BBBBBB" "BBBBBB.1" "BBBBBB.2"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.