SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
Josh
Calcite | Level 5
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.
4 REPLIES 4
Patrick
Opal | Level 21
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
Josh
Calcite | Level 5
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 🙂
Patrick
Opal | Level 21
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
Josh
Calcite | Level 5
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.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

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
  • 4 replies
  • 3691 views
  • 0 likes
  • 2 in conversation