BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
mvalsamis
Obsidian | Level 7

I have two identical tables, WORK.ONE and WORK.TWO (this is only for simplicity). The code to create them and assign them indexes is the following:

data work.one;
  length id $2 product $5 price 8;
  input id $ product $ price;
  datalines;
  A3 Desk 500
  A4 Table 1000
  B1 Bed 1500
  ;
run;

data work.two;
  length id $2 product $5 price 8;
  input id $ product $ price;
  datalines;
  A3 Desk 500
  A4 Table 1000
  B1 Bed 1500
  ;
run;

proc datasets lib=work;
  modify one;
  index create id;
run;

proc datasets lib=work;
  modify two;
  index create id;
run;

 

I want to compare them using PROC COMPARE as follows:

proc compare b=one c=two;
  id id;
run;

I get the following results, again simplified:

 

Variables with Unequal Values

 

Variable   Type         Len        Ndif        MaxDif

price          NUM       $2           1              3.5E-20

 

Value Comparison Results for Variables

 

id       ||    Base             Compare                       Diff.                      %Diff

                 price             price

----------------------------------------------------------------------- 

A4     ||  1000              1000                             3.5E-20              1.3E-20

 

Although the values are identical, they are not recognised like that. Obviously the difference tends to zero, but I need it to be shown as exactly equal. Do you have any idea of how I can fix this? Thanks a lot in advance.

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kathryn_SAS
SAS Employee

Another option to account for numeric precision issues is to use the ROUND function on the variable (Price) in advance in each data set.

data one;
set one;
price=round(price,.01);
run;

data two;
set two;
price=round(price,.01);
run;

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Clearly the difference is very small: 3.5E-20. Why does this happen? Because computers cannot represent some non-integer numbers with infinite precision, and so these will show as different. (I do not get the results you show from your code, indicating that your real-world data that you ran PROC COMPARE on did not have integers for PRICE)

 

To avoid this problem, use the FUZZ= option in PROC COMPARE.

 

--
Paige Miller
mvalsamis
Obsidian | Level 7

Yes, this example is oversimplified, and if you compare the two tables, they will be exactly identical. The actual tables I am working in have 24 numeric variables, which have decimals.

Kathryn_SAS
SAS Employee

Another option to account for numeric precision issues is to use the ROUND function on the variable (Price) in advance in each data set.

data one;
set one;
price=round(price,.01);
run;

data two;
set two;
price=round(price,.01);
run;
How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 969 views
  • 3 likes
  • 3 in conversation