data test;
set test2;
diff = t1 - t2;
run;
sample data
t1 t2 diff
12 6 6
14191.65 14191.65 1.818989E-12
The issue is whenever I encounter a large number the difference is reflected as scientific notation where as it should be a 0
I used
proc format;
picture mynum
low - high = '000000000009';
run;
The number displays as a 0 however when I apply a test such as
if diff = 0 then delete; The test fails and the row still appears
any ideas
Welcome to computing 🙂
This is a known 'issue'. Please see the full explanation below.
You can resolve this by formatting your data, using something like 8.1 should be enough.
And you can change your test to:
if round(value, 0.0001) = 0 then <action>;
Just responded to a similar question in a different thread. The topic you want to Google is numeric precision. It's not just with SAS, but any computer.
The numbers are likely to be off somewhere off to the right decimal place. The solution is to round the numbers to the number of decimal points that are practically significant to whatever you're doing.
Art, CEO, AnalystFinder.com
Could you please try the below approach
data test;
set test2;
diff = t1 - t2;
format diff mynum.;
if compress(put(diff,best.))='0' then delete;
run;
As the others have already noted, this is an artifact resulting from the way SAS stores numeric values.
Adapt your data step (and other steps that do similar calculations):
data test;
set test2;
diff = round(t1 - t2,.00001);
run;
And you'll get rid of problems caused by precision overflows or numbers that are periodic in binary representation.
BTW your example data is wrong because you let a very likely default format of best8. display the values of t1 and t2.
I know this because when I copy your pasted example data and use that in a data step the result is 0.
data example; x=14191.65; y=14191.65; result = y-x; put result= best32.; run;
In addition to what others have said, you should avoid testing floating-point values for equality. Instead, test whether the value is within a small amount of the target value:
if fabs(diff) < 1e-6 then delete;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.