Help using Base SAS procedures

Invalid numeric data ??

Accepted Solution Solved
Reply
Super Contributor
Posts: 396
Accepted Solution

Invalid numeric data ??

I don't understand why when I'm running this code

if CMANAME = 'Ottawa - Gatineau (QC/ON)' and substr (FSA,1,1) = 'J' then Province = 'Quebec' and CMA_NAME='Quebec';

I get this error:

NOTE: Invalid numeric data, 'Quebec' , at line 145 column 85.

FSALDU=J0X0A1 FSA_LDU=J0X 0A1 FSA=J0X COMMNAME=WAKEFIELD PRCDDA=24820077 PRCDCSD=2482035

CSDNAME=La P?che (QC) CMACA=505 CMANAME=Ottawa - Gatineau (QC/ON) PROV=QC FILE_VINTAGE=2011 JUL

PC_VINTAGE=2011 MAY CMA_NAME=Quebec CMA_NAME2=Ottawa - Gatineau (QC Province=0 _ERROR_=1

_N_=229242

when Province is text and considered text in the earlier part of the code..

Thanks


Accepted Solutions
Solution
‎05-07-2012 09:44 AM
Contributor
Posts: 45

Re: Invalid numeric data ??

change

then Province = 'Quebec' and CMA_NAME='Quebec'

to

then do;

Province = 'Quebec';

CMA_NAME='Quebec';

end;

View solution in original post


All Replies
Super Contributor
Posts: 1,636

Re: Invalid numeric data ??


run

proc contents data=yourdataset;run;

to check variable "procvince" is a numeraic variable or character variable.

Super Contributor
Posts: 396

Re: Invalid numeric data ??

Province   Char   27

But Province is being created by me in the step.

Solution
‎05-07-2012 09:44 AM
Contributor
Posts: 45

Re: Invalid numeric data ??

change

then Province = 'Quebec' and CMA_NAME='Quebec'

to

then do;

Province = 'Quebec';

CMA_NAME='Quebec';

end;

Super Contributor
Posts: 396

Re: Invalid numeric data ??

Thank you

Super User
Posts: 5,099

Re: Invalid numeric data ??

You've gotten the right solution, but ...

Your original question also asked why you were getting the results about invalid numeric data.  Here's the explanation for that.

As noted, when there is no DO group, SAS expects just a single outcome.  So the statement is interpreted as if you had added parentheses:

if ... then Province = ( 'Quebec' and CMA_NAME='Quebec' );

With a set of conditions joined by AND, SAS attempts to evaluate each as true or false.  It has a scheme for evaluating the values it encounters, using 0 or missing as false, and any other numeric value as true.  'Quebec' is none of the above, and therefore constitutes an invalid numeric value.  You could actually run this statement without error:

if name='podarum' then salary=1000000 and age=52;

SAS interprets 1000000 as true, and SALARY receives a value of 1 when AGE=52, and 0 when AGE= any other value.

Hope this helps, rather than confuses the issue.

Good luck.

Super Contributor
Posts: 396

Re: Invalid numeric data ??

Thanks for the explanation Astounding, it helps to know the reason behind it.

Contributor
Posts: 45

Re: Invalid numeric data ??

nice explanation...

Super Contributor
Posts: 1,636

Re: Invalid numeric data ??

Hi Astounding,

Are you a teacher?

Super User
Posts: 5,099

Re: Invalid numeric data ??

Linlin,

In general, I have to remain 100% anonymous.  Anything short of that would jeopardize (or at least extremely limit) my ability to post here.  So regretfully (as you have seen elsewhere), I don't respond to any requests that might endanger that.

Having said that, I suspect that the answer is pretty clear and will confirm just this much.  I am not a teacher by any sort of formal training, but I have taught SAS courses.

Good luck and please understand.

Super Contributor
Posts: 1,636

Re: Invalid numeric data ??

Thank you!!! We are so luck to have you on the forumSmiley Happy.

N/A
Posts: 1

Re: Invalid numeric data ??

I'm getting the same message in my code, but I have only one outcome in my if-then condition and that is to assign a value to a character variable.

NOTE: Invalid numeric data, key2='COBRIE' , at line 1 column 2.

NOTE: Invalid numeric data, name2='COBRIE' , at line 1 column 2.

NOTE: Invalid numeric data, vre_first_name='CHRISTOPHER' , at line 1 column 2.

NOTE: Invalid numeric data, vre_last_name='OBRIEN' , at line 1 column 2.

vre_last_name=OBRIEN vre_first_name=CHRISTOPHER dob=.

  key1=  key2=COBRIE fname10=  fname_match=  name_match=4 dob_match=0

name1=  name2=COBRIE

🔒 This topic is solved and locked.

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

Discussion stats
  • 11 replies
  • 6155 views
  • 2 likes
  • 5 in conversation