DATA Step, Macro, Functions and more

Invalid numeric data error

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Invalid numeric data error

I am getting the error message: NOTE: Invalid numeric data, 'EFT/150405' , at line 13 column 15. 

 

Here is the SAS code:

10           INFILE FILEIN FIRSTOBS=3;
11           INPUT @3 V_PRO $CHAR10.
12                 @14 V_SUF $CHAR02.;
13             IF V_PRO <> ' '
14             THEN OUTPUT;

 

Why would I get an error for invalid numeric data when the variable is defined as $CHAR10.?


Accepted Solutions
Solution
‎01-24-2017 01:40 PM
Valued Guide
Posts: 797

Re: Invalid numeric data error

YOu have just revealed a property of the <> operator vs. the ^= operator.   The earlier apparently only works for numeric data.  Change you condition to

   IF V_PRO ^= ' ';

 

 

View solution in original post


All Replies
Solution
‎01-24-2017 01:40 PM
Valued Guide
Posts: 797

Re: Invalid numeric data error

YOu have just revealed a property of the <> operator vs. the ^= operator.   The earlier apparently only works for numeric data.  Change you condition to

   IF V_PRO ^= ' ';

 

 

Super Contributor
Posts: 251

Re: Invalid numeric data error

Just to be more explicit: <> returns the maximum value of two variables (>< is the minimum). It's a long-standing SAS operator: it still works like this in data steps, but is problematic.

Valued Guide
Posts: 797

Re: Invalid numeric data error

thanks for the needed clarification.

Super User
Posts: 10,500

Re: Invalid numeric data error

YOu might also want to consider the advantages of using the Missing function. It doesn't care what type the variable is so you can use:

 

If missing(var) then .... ;

or

If not missing(var) then ....;

Respected Advisor
Posts: 3,777

Re: Invalid numeric data error


mwhsas wrote:

I am getting the error message: NOTE: Invalid numeric data, 'EFT/150405' , at line 13 column 15. 

 

Here is the SAS code:

10           INFILE FILEIN FIRSTOBS=3;
11           INPUT @3 V_PRO $CHAR10.
12                 @14 V_SUF $CHAR02.;
13             IF V_PRO <> ' '
14             THEN OUTPUT;

 

Why would I get an error for invalid numeric data when the variable is defined as $CHAR10.?


You also get a note that tells you that <> is not the NOT operator. 

NOTE: The "<>" operator is interpreted as "MAX".

 

Super User
Super User
Posts: 6,500

Re: Invalid numeric data error

[ Edited ]

SAS is converting your character variable's value to a number because you used a character expression as the condition to be evaluated.  In this statement you are using the MAX operator, so 

IF V_PRO <> ' ' THEN OUTPUT;

is the same as 

IF max(V_PRO,' ') THEN OUTPUT;

Correction: That is if the MAX() function worked on character strings the same way that the <> (max) operator does.

 

Since the value of V_PRO was greater than a space SAS tried to convert it to a number so it could test if it true, that is not zero.

 

Perhaps you meant to test if variable was not all blanks?  There are many ways to do that but using the MAX() operator is not one of them.

IF V_PRO ne ' ' THEN OUTPUT;
IF V_PRO ^= ' ' THEN OUTPUT;
IF not (V_PRO = ' ') THEN OUTPUT;
IF not missing(V_PRO) THEN OUTPUT:
IF V_PRO = ' ' THEN ; ELSE OUTPUT; 

 

Respected Advisor
Posts: 3,777

Re: Invalid numeric data error


Tom wrote:

SAS is converting your character variable's value to a number because you used a character expression as the condition to be evaluated.  In this statement you are using the MAX operator, so 

IF V_PRO <> ' ' THEN OUTPUT;

is the same as 

IF max(V_PRO,' ') THEN OUTPUT;

Since the value of V_PRO was greater than a space SAS tried to convert it to a number so it could test if it true, that is not zero.

 

Perhaps you meant to test if variable was not all blanks?  There are many ways to do that but using the MAX() operator is not one of them.

IF V_PRO ne ' ' THEN OUTPUT;
IF V_PRO ^= ' ' THEN OUTPUT;
IF not (V_PRO = ' ') THEN OUTPUT;
IF not missing(V_PRO) THEN OUTPUT:
IF V_PRO = ' ' THEN ; ELSE OUTPUT; 

 


I would not say that MAX operator is the same as MAX function as the function requires numeric arguments.

 

25         data _null_;
26            x = 'A' <> 'B';
NOTE: The "<>" operator is interpreted as "MAX".
27            y = max('A','B');
28            put _all_;
29            run;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      27:12   27:16   
NOTE: Invalid numeric data, 'A' , at line 27 column 12.
NOTE: Invalid numeric data, 'B' , at line 27 column 16.
x=B y=. _ERROR_=1 _N_=1
x=B y=. _ERROR_=1 _N_=1
Super User
Super User
Posts: 6,500

Re: Invalid numeric data error

Good to know if you did want to take the max of two character strings.

 

So the <> operator is overloaded and can be used for both numeric and character operands, but the MAX() function is not.  So the MAX() function is more like the INPUTN() function than the INPUT() function.

 

 

Respected Advisor
Posts: 3,777

Re: Invalid numeric data error


Tom wrote:

Good to know if you did want to take the max of two character strings.

 

So the <> operator is overloaded and can be used for both numeric and character operands, but the MAX() function is not.  So the MAX() function is more like the INPUTN() function than the INPUT() function.

 

 


Yes I think overloaded describes it.  I wonder if overloading was a computer science term when Tony Barr wrote the code for the MIN an MAX operators.

New Contributor
Posts: 2

Re: Invalid numeric data error

This is all great information. I thank you all very much. Obviously, I am not an experienced SAS programmer. For my program, I simply changed <> to NE and got the desired results. I was just checking for blanks in the input field.

☑ This topic is SOLVED.

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

Discussion stats
  • 10 replies
  • 378 views
  • 1 like
  • 6 in conversation