I need to derive a table in SAS Viya that is derived from Teradata external database. Then I need to create another table were I compare two variables of the former table, but the comparison is not done correctly. Specifically, I may have 2 equal values, but they are regarded as unequal. Let me write a simplified example to explain you:
proc sql;
connect to teradata (<credentials>);
create table work.derived as
select id informat=6. format=6. length=8,
total_amount informat=19.2 format=19.2 length=8,
mean_amount informat=19.2 format=19.2 length=8
from connection to teradata (
select top 1 teradata_view."id",
teradata_view."total_amount",
teradata_view."mean_amount"
from "teradata_catalog"."teradata_view"
where date='2025-09-09');
disconnect from teradata;
quit;
The table WORK.DERIVED is generated (example):
id |
total_amount |
mean_amount |
567912 |
7.38 |
7.38 |
Then, I need to create the table WORK.COMPARISONS
data work.comparisons;
set work.derived;
if total_amount > mean_amount then flag=1;
else flag=0;
run;
The table WORK.COMPARISONS is created as follows:
id |
total_amount |
mean_amount |
flag |
567912 |
7.38 |
7.38 |
1
|
As you see, flag=1, which is wrong. It should be flag=0. I tried increasing the decimals in the format and informat (e.g. 23.4) or remove the format and informat, but the results are exactly the same. Do you have any idea where this error comes from and how I can best solve it? Thank you in advance!