DATA Step, Macro, Functions and more

Negative zero

Reply
Occasional Contributor
Posts: 11

Negative zero

A colleague had a proc summary where a total count of positive and negative counts was zero on the data sheet in EG. The data manually pointed to a net result of zero. The total became a denominator in a percentage calculation and the business rule was to use the usual formula when the total was positive, a flag value when negative and a different flag value when it was zero. She used a SELECT and the negative flag value was produced instead of the zero flag value. We expanded the when (value < 0) statement out and putlog in each case printed zero using n=. The variable summed positive and negative whole numbers so floating point shouldn't have been a problem but tried k=fuzz(n) an putting y= and still got zero. Did an x=put(n, E12.) and putlog x= gave a left adjusted '0'. All this was in the do;...end; following the test on being less than zero.

I recall seeing reference to -0 being produced by proc summary and being displayed as '0' but taken to be less than plain vanilla 0 in SAS. I can't help wondering if this is such a case.
Respected Advisor
Posts: 3,902

Re: Negative zero

Hi

If this is a precision problem of some kind use a round() function before doing the comparison, i.e. round(value,0.00001)<0.

I've seen such cases with data coming from DB2 and the issue was caused by the way data is stored in DB2 compared to SAS.

HTH
Patrick
Occasional Contributor
Posts: 11

Re: Negative zero

Thanks Patrick. It was the sum of integer counts so there shouldn't be any floating point issues. I'll check the manual for a hex format that may reveal the bit pattern and compare with the pattern for zero. Applying the ROUND or FUZZ function may also by forcing it to be zero, help or even adding 1 and comparing with 1 then subtracting the 1. We were scratching our heads till near 7:30pm Friday night before we thought it could wait till Monday Smiley Happy
Respected Advisor
Posts: 3,902

Re: Negative zero

data _null_;

value=0;
/* value=1/(10**200);*/

put "BEST32. for value " value best32. /;
if value=0 then put "Hex for value = 0 : " value hex16.;
else put "HEX for value ^= 0 : " value hex16.;
run;


HTH
Patrick
Occasional Contributor
Posts: 11

Re: Negative zero

Problem solved. My colleague had set "options missing=0" and the value was missing rather than negative zero. I suggested she only use it in future just before ODS and then immediately issue "options missing=". again. A very dangerous option IMO. Seeing a '.' tells me I have my merges/joins wrong and that is important.
Ask a Question
Discussion stats
  • 4 replies
  • 742 views
  • 0 likes
  • 2 in conversation