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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Jay_TxOAG
Quartz | Level 8

change

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

to

then do;

Province = 'Quebec';

CMA_NAME='Quebec';

end;

View solution in original post

11 REPLIES 11
Linlin
Lapis Lazuli | Level 10


run

proc contents data=yourdataset;run;

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

podarum
Quartz | Level 8

Province   Char   27

But Province is being created by me in the step.

Jay_TxOAG
Quartz | Level 8

change

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

to

then do;

Province = 'Quebec';

CMA_NAME='Quebec';

end;

podarum
Quartz | Level 8

Thank you

Astounding
PROC Star

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.

podarum
Quartz | Level 8

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

Jay_TxOAG
Quartz | Level 8

nice explanation...

Linlin
Lapis Lazuli | Level 10

Hi Astounding,

Are you a teacher?

Astounding
PROC Star

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.

Linlin
Lapis Lazuli | Level 10

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

ethom1906
Calcite | Level 5

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

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 11 replies
  • 9869 views
  • 2 likes
  • 5 in conversation