Date: Thu, 3 Nov 2005 12:02:25 -0600
Reply-To: PuddingDotManAtGmailDotCom@listserv.cc.uga.edu
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Pudding Man <pudding.man@GMAIL.COM>
Subject: Re: Trying to avoid division by zero...
In-Reply-To: <01e801c5dff0$85f15d20$6502a8c0@speedy>
Content-Type: text/plain; charset=ISO-8859-1
On 11/2/05, Kevin Myers <KMyers@procominc.net> wrote:
> By the way, here is an only slightly uglier macro to get around division by
> zero messages within expressions, if you really need to:
>
> %macro zdiv(n,d);
> ifn(&d,(&n)/ifn(&d,&d,1),.)
> %mend zdiv;
>
> Usage example:
>
> data _null_;
> do d=0 to 5;
> r=%zdiv(1,d);
> put d= r=;
> end;
> run;
--- snip ---
It is very clever (compliments).
It works!
It seems to use about 2.6 times the cpu cycles of an equivalent
IF/THEN/ELSE construct in a simple test. Particularly for folks
that have neither beau coup fractions to compute nor tons of
data, performance would not be an issue.
Cheers,
Puddin'
*****************************************************************
*** Puddin' Man PuddingDotMan at GmailDotCom **
*****************************************************************;
|