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
change
then Province = 'Quebec' and CMA_NAME='Quebec'
to
then do;
Province = 'Quebec';
CMA_NAME='Quebec';
end;
run
proc contents data=yourdataset;run;
to check variable "procvince" is a numeraic variable or character variable.
Province Char 27
But Province is being created by me in the step.
change
then Province = 'Quebec' and CMA_NAME='Quebec'
to
then do;
Province = 'Quebec';
CMA_NAME='Quebec';
end;
Thank you
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.
Thanks for the explanation Astounding, it helps to know the reason behind it.
nice explanation...
Hi Astounding,
Are you a teacher?
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.
Thank you!!! We are so luck to have you on the forum.
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
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 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.
Ready to level-up your skills? Choose your own adventure.