Desktop productivity for business analysts and programmers

SAS Proc Report Decimal point highlight issue

Accepted Solution Solved
Reply
Contributor
Posts: 24
Accepted Solution

SAS Proc Report Decimal point highlight issue

[ Edited ]

deleted


Accepted Solutions
Solution
‎01-31-2018 05:50 AM
Super User
Super User
Posts: 8,260

Re: SAS Proc Report Decimal point highlight issue

Posted in reply to srinidelite

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;

image.png

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;

image.png

 

View solution in original post


All Replies
PROC Star
Posts: 1,332

Re: SAS Proc Report Decimal point highlight issue

Posted in reply to srinidelite

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

Solution
‎01-31-2018 05:50 AM
Super User
Super User
Posts: 8,260

Re: SAS Proc Report Decimal point highlight issue

Posted in reply to srinidelite

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;

image.png

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;

image.png

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 190 views
  • 0 likes
  • 3 in conversation