BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mwhsas
Calcite | Level 5

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.?

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

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 ^= ' ';

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

10 REPLIES 10
mkeintz
PROC Star

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 ^= ' ';

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
LaurieF
Barite | Level 11

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.

mkeintz
PROC Star

thanks for the needed clarification.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ballardw
Super User

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 ....;

data_null__
Jade | Level 19

@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".

 

Tom
Super User Tom
Super User

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; 

 

data_null__
Jade | Level 19

@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
Tom
Super User Tom
Super User

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.

 

 

data_null__
Jade | Level 19

@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.

mwhsas
Calcite | Level 5

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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