05-07-2012 09:26 AM
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
when Province is text and considered text in the earlier part of the code..
05-07-2012 10:42 AM
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.
05-07-2012 11:29 AM
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.
11-29-2012 04:10 PM
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
Need further help from the community? Please ask a new question.