Hi,
While I ran below code, getting value of variable TAG1 as "unchecked" , eventhough values are getting same for TAG and TAG2. Value for TAG1 is not getting correct according to if condition.
Any idea why is happening so?
Data readin2;
a=6882;
b=9176;
c=68.82;
d=91.76;
format TAG TAG2 12.8;
TAG=a/b;
TAG2=c/d;
length TAG1 $20;
IF TAG = TAG2 THEN TAG1 = "New";
ELSE TAG1 ="Unchecked";
run;
The problem is that SAS numbers are stored as base 2 floating points, meaning that the decimals cannot be represented exactly. This means that the may be a minuscule difference between the calculation with the integers and the decimal values.
Try something like:
Data readin2;
a=6882;
b=9176;
c=68.82;
d=91.76;
format TAG TAG2 12.8;
TAG=a/b;
TAG2=c/d;
length TAG1 $20;
IF abs(TAG-TAG2)<1e-10 THEN TAG1 = "New";
ELSE TAG1 ="Unchecked";
run;
Add this to your code, and you'll get a clue:
diff = tag - tag2;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.