DATA Step, Macro, Functions and more

Pulling Out Numeric Values from a Character Variable

Accepted Solution Solved
Reply
Regular Contributor
Posts: 220
Accepted Solution

Pulling Out Numeric Values from a Character Variable

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?

 

LABVALNUMLABCHARLAB
77 
NEG NEG
-3-3 
+ +
2-4 2-4
1.51.5 
2+ 2+
98.698.6 
12.77312.773 
YELLOW YELLOW
< 2.5 < 2.5

Accepted Solutions
Solution
‎08-25-2016 09:22 AM
Super User
Posts: 5,085

Re: Pulling Out Numeric Values from a Character Variable

The easiest way would be to suppress all the usgly messages about invalid data:

 

numlab = input(labval, ??12.);

View solution in original post


All Replies
Solution
‎08-25-2016 09:22 AM
Super User
Posts: 5,085

Re: Pulling Out Numeric Values from a Character Variable

The easiest way would be to suppress all the usgly messages about invalid data:

 

numlab = input(labval, ??12.);

Regular Contributor
Posts: 220

Re: Pulling Out Numeric Values from a Character Variable

I was never aware of the ? and ?? format modifier until now.  Thank you so much!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 185 views
  • 0 likes
  • 2 in conversation