Is there a function to replace all characters that are not letters, numbers or underscores, to an underscore?
I am nearly certain i've run across one before, and used it. But I have been unable to find it again.
I recall the function having at least 3 arguments, one of them being modifiers, allowing you to select all letters and numbers to the list of acceptable characters.
I thought it was TranWrd but that does not have a modifiers argument. Same with Translate.
any ideas?
If you are getting such characters in variable names then it has something with how you are reading the data and I strongly suspect Proc Import.
Very simple to prevent: Options validvarname=V7;
prior to proc import.
That will force Proc import to create variable names compatible with the SAS version 7, i.e. no characters other than letters, digits and _.
Much easier to prevent than to correct later.
NLITERAL function?
NVALID function may also be useful.
COMPRESS() is the only function I can think that comes close to what you've described but I agree with @ballardw that changing how you import your data is a better overall solution.
You can always do:
str_ = prxchange("s/[[:^alnum:]]/_/o", -1, strip(str));
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.