deleted
You are rounding in the wrong place. Let's convert your test data into a dataset and try to report it. First let's show the value of the actual difference between the absolute values and then round that difference.
data have ;
input Value1 Value2 ExpectedDiff ;
copy2=value2;
diff1=abs(value1)-abs(value2) ;
diff2=round(diff1,0.01);
format diff: 20.17 ;
cards;
62.21 -62.22 -0.01
65.89 -65.88 0.01
-78.3 78.39 -0.09
-89.87 89.85 0.02
. . .
;
proc print data=have ;
run;
Now let's try it with PROC REPORT.
proc report data=have ;
define _all_ / display ;
compute value2 ;
if abs(round(abs(value1)-abs(value2),0.01)) > 0.01 then
call define (_col_,"style","style={background= orange}")
;
endcomp;
compute copy2;
if ((abs(round(value1,0.01)) - abs(round(value2,0.01)) < -0.01)
or (abs(round(value1,0.01)) - abs(round(value2,0.01)) >0.01)) then
call define (_col_,"style","style={background= orange}")
;
endcomp;
run;
For the columns in AMTPREMIUM_QIS that appear to be improperly flagged, I believe that you've run into the problem with floating point variables that decimals can't be exactly represented in binary.
data Demonstrate;
AMTPREMIUM = 62.34;
AMTPREMIUM_6970CarGlass = 62.33;
if AMTPREMIUM - AMTPREMIUM_6970CarGlass > .01 then
Flag1 = 1;
else Flag1 = 0;
if AMTPREMIUM - AMTPREMIUM_6970CarGlass > .011 then
Flag2 = 1;
else Flag2 = 0;
putlog Flag1= Flag2=;
run;
On your AMTEXTFORPAYPERI_QIS issue, because AMTEXTFORPAYPERI is missing, the entire equation will come out to missing, and I believe that missing values are considered less than any number.
Tom
You are rounding in the wrong place. Let's convert your test data into a dataset and try to report it. First let's show the value of the actual difference between the absolute values and then round that difference.
data have ;
input Value1 Value2 ExpectedDiff ;
copy2=value2;
diff1=abs(value1)-abs(value2) ;
diff2=round(diff1,0.01);
format diff: 20.17 ;
cards;
62.21 -62.22 -0.01
65.89 -65.88 0.01
-78.3 78.39 -0.09
-89.87 89.85 0.02
. . .
;
proc print data=have ;
run;
Now let's try it with PROC REPORT.
proc report data=have ;
define _all_ / display ;
compute value2 ;
if abs(round(abs(value1)-abs(value2),0.01)) > 0.01 then
call define (_col_,"style","style={background= orange}")
;
endcomp;
compute copy2;
if ((abs(round(value1,0.01)) - abs(round(value2,0.01)) < -0.01)
or (abs(round(value1,0.01)) - abs(round(value2,0.01)) >0.01)) then
call define (_col_,"style","style={background= orange}")
;
endcomp;
run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.