I have a list of lab values in a character variable, and I need to store all the numeric values in a numeric variable. I thought I had it made when I found the NOTDIGIT() function. That works great for integer data, but then I realized that I am dealing with decimal and negative values. Is there a way to detect just these characters? I know I could just use INPUT(). That would convert any number-like value to numeric, but for all the character values, I would be left with a lot of ugly notes filling up my log (NOTE: Invalid argument to function INPUT at line XXX column YYY.).
I have some example data below. Is there away to get LABVAL to the NUMLAB and CHARLAB, respectively, as I have them?
| LABVAL | NUMLAB | CHARLAB |
| 7 | 7 | |
| NEG | NEG | |
| -3 | -3 | |
| + | + | |
| 2-4 | 2-4 | |
| 1.5 | 1.5 | |
| 2+ | 2+ | |
| 98.6 | 98.6 | |
| 12.773 | 12.773 | |
| YELLOW | YELLOW | |
| < 2.5 | < 2.5 |
The easiest way would be to suppress all the usgly messages about invalid data:
numlab = input(labval, ??12.);
The easiest way would be to suppress all the usgly messages about invalid data:
numlab = input(labval, ??12.);
I was never aware of the ? and ?? format modifier until now. Thank you so much!
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.