LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (June 1996, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 20 Jun 1996 09:09:51 -0400
Reply-To:   CGASPINA@AM.PNU.COM
Sender:   "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:   CGASPINA@AM.PNU.COM
Subject:   Re[5]: Is this a bug???

I'm sending this on to SAS-L so all can benefit.

______________________________ Forward Header __________________________________ Subject: Re[5]: Is this a bug??? Author: hermans1@westatpo.westat.com at INTERNET Date: 6/19/96 7:04 PM

I've attached Ian's qualifications of the solution. I believe that the format will work for larger or smaller numbers so long as you specify the appropriate format. Ian's solution has more general applicability (although the put with format method also allows one to specify user-defined formats as well as default formats). Sig ______________________________________________________________________

Sigurd,

IF round(x,.01)=round(y,.01) THEN .......;

accomplishes the same thing but is a little faster because the format needs to both round and convert to character. It is also more general in that it works for numbers over one million and under -100000.

Ian [Whitlock /Westat]

----------------------------------------------------------------------

That is such a simple solution that works beautifully. Anyone know of any situation where this wouldn't work? It does require that you specify a level of precision to do your comparison, but for my usage it would work perfectly. Wow - talk about using the right tool for the right job. Thanks!

============================================================ == Clifford Aspinall cgaspina@pwinet.upj.com (work) === == Kalamazoo, Michigan cgaspina@net-link.net (home) === == Disclaimer: Any opinions expressed are not === == necessarily mine or my employers === ============================================================

______________________________ Reply Separator _________________________________ Subject: Re[3]: Is this a bug??? Author: hermans1@WESTATPO.WESTAT.COM at INTERNET Date: 6/19/96 3:11 PM

I have always wondered about comparisons of floating point numbers in SAS. The

problem seems even worse when we export data from one platform to another. When in doubt, I compare the converted string values of numbers, as in ...

IF put(x,8.2)=put(y,8.2) THEN .......;

Fortran and C programmers have learned to avoid direct comparisons of FP numbers. The widespread use of type number variables for storing categorical codes in SAS datasets makes it more difficult to avoid these questionable forms

of comparisons in SAS programs. Any other ideas? Sig Hermansen

______________________________ Reply Separator _________________________________ Subject: Re[2]: Is this a bug??? Author: WHITLOI1 at REC Date: 06/19/96 12:50 PM

Subject: Re: Is this a bug??? Summary: Simple problems need simple solutions. Respondent: Ian Whitlock <whitloi@westat.com>

In response to Andy Yuan's <ANDY_YUAN@SMTPLINK.MSSM.EDU> question why the test

> DATA TEST1; SET Q1; IF PERCENT EQ 100; RUN; RUN; DATA TEST2; SET Q1; > IF PERCENT GT 100; RUN;

failed when PERCENT had the value 100 when viewed with the format 20.16 Clifford Aspinall <CGASPINA@AM.PNU.COM> responded with a macro %CMP to compare real values. Since the answer to real comparisons amounts to rounding the values compared, I am not sure that a macro is needed, but if one is to be used it should be simple.

%macro cmp (cond) / parmbuff ; %let cond = %qsubstr(%quote(&syspbuff),2,%length(&syspbuff)-2) ; %let cond = %quote(&cond) ; %unquote(round(%scan(&cond,1,%str( )),1e-12) %scan(&cond,2,%str( )) round(%scan(&cond,3,%str( )),1e-12)) %mend cmp ;

The parmbuff option is needed to avoid having the call %CMP ( A = 1 ) result in the error message that the keyword A is not defined. The macro above assumes an expression of the form EXP OPERAND EXP where EXP represents an arithmetic expression with no internal blanks and OPERAND is an arithmetic comparison operator. The quoting functions are used to handle people who make tests like

data _null_; or = 3 ; ne = 1.7+.3 ; if %cmp ( or eq ne+1 ) then put 'ok' ; run ;

Ian Whitlock


Back to: Top of message | Previous page | Main SAS-L page