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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.