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 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 ^= ' ';
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 ^= ' ';
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.
thanks for the needed clarification.
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 ....;
@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".
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;
@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
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.
@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.
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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.