I was surprised that to see that the following code will give no errors
DATA X;
set y;
if var1 = "1";
run;
I have run something similar where var1 is numeric and yet SAS compiles and executes the code without error. I thought that you could get an error if var1 was defined to be a numeric variable. Was I wrong about this?
You will see a SAS NOTE (no ERROR) in your SASLOG indicating that SAS converted character to numeric or vice versa, depending on the condition presented.
On the other hand, if you attempt to combine SAS data sets which have same-named variables and different types, you will get a SAS error in the DATA step.
I understand that but how come SAS allows the IF statement to operate normally and give you the correct results even though VAR1 is a numeric type and I am using a string "4" in it to subset the data set. Shouldn't it have detected that VAR1 was numeric and therefore I cannot use the string "4" with VAR1. I found that behavior very strange. Maybe it was there all the time and now I am just noticing.
Message was edited by: sjm500
Message was edited by: sjm500
Again, the SASLOG NOTE is the only indication, as demonstrated below:
1 data _null_;
2 if 1 = '1' then putlog 'We have a winner!';
3 run;
NOTE: Character values have been converted to numeric values at the places given by:
(Line):(Column).
2:8
We have a winner!
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds