[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sas-l
Subject:    Re: DIVIDE function results
From:       Bartosz_Jabłoński <yabwon () GMAIL ! COM>
Date:       2023-06-03 8:21:02
Message-ID: CAMJ3xTMSwodWRkA_8TJ5sO9WpAhwiz9+87UC2Z_PQrFpx48fjQ () mail ! gmail ! com
[Download RAW message or body]

I dare to say, my "ifn ( Y ,  Divide (X,Y) , . )" went the best ;-) ;-) ;-)

Bart

Code:

%macro test()/parmbuff;
data _null_;
  do i=1 to 1e8;
    y=0;
    do x=-1,1,0,.A,.Z;
      z=&syspbuff.;
    end;
    y=2500;
    x=5000;
    z=&syspbuff.;
  end;
run;

%mend test;



%test(.);
%test(dividE((y ne 0)*x, y));
%test(coalesce(. ,divide(X,Y)));
%test(min (divide (X,Y) ));
%test( min (. , divide (X,Y) ));
%test(ifn ( Y ,  Divide (X,Y) , . ))

Log:

1312   %macro test()/parmbuff;
1313   data _null_;
1314     do i=1 to 1e8;
1315       y=0;
1316       do x=-1,1,0,.A,.Z;
1317         z=&syspbuff.;
1318       end;
1319       y=2500;
1320       x=5000;
1321       z=&syspbuff.;
1322     end;
1323   run;
1324
1325   %mend test;
1326
1327
1328
1329   %test(.);

NOTE: DATA statement used (Total process time):

*real time           1.01 seconds      user cpu time       1.01 seconds*
      system cpu time     0.00 seconds
      memory              318.31k
      OS Memory           27644.00k


1330   %test(dividE((y ne 0)*x, y));

NOTE: Missing values were generated as a result of performing an operation
on missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      200000000 at 1:17
NOTE: DATA statement used (Total process time):

*      real time           5.49 seconds      user cpu time       5.48
seconds*
      system cpu time     0.00 seconds
      memory              318.31k
      OS Memory           27644.00k


1331   %test(coalesce(. ,divide(X,Y)));

NOTE: DATA statement used (Total process time):

*      real time           4.44 seconds      user cpu time       4.43
seconds*
      system cpu time     0.00 seconds
      memory              318.31k
      OS Memory           27644.00k


1332   %test(min (divide (X,Y) ));

NOTE: Missing values were generated as a result of performing an operation
on missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      500000000 at 1:2
NOTE: DATA statement used (Total process time):

*     real time           6.93 seconds      user cpu time       6.93
seconds*
      system cpu time     0.01 seconds
      memory              318.31k
      OS Memory           27644.00k


1333   %test( min (. , divide (X,Y) ));

NOTE: Missing values were generated as a result of performing an operation
on missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      500000000 at 1:3
NOTE: DATA statement used (Total process time):

*     real time           6.91 seconds      user cpu time       6.93
seconds*
      system cpu time     0.04 seconds
      memory              318.31k
      OS Memory           27644.00k


1334   %test(ifn ( Y ,  Divide (X,Y) , . ))

NOTE: DATA statement used (Total process time):

*      real time           4.29 seconds      user cpu time       4.28
seconds*
      system cpu time     0.03 seconds
      memory              318.31k
      OS Memory           27644.00k



<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
 Virus-free.www.avg.com
<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
 <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

pt., 2 cze 2023 o 03:35 Mark Keintz <mkeintz@outlook.com> napisał(a):

> Jean-Claude:
> 
> 
> 
> I suspect you might get a better set of measures on comparative formula
> performance if dataset BRUCE were a lot larger.  Most of the time taken to
> process this sample data set (6 obs) probably was in compiling and setting
> up the data step, which is not the component you want to measure.  Multiply
> the dataset size by some large multiplier.
> 
> 
> 
> You could further de-confound the test.  Eliminate all the data input
> processing and embed the formulas in loops.  I used the same values as
> dataset BRUCE, with a multiplier of 10,000,000 for one of the formulas
> below.  The real time use was 0.65 seconds.   I didn't know how fast it
> would be, so I tested with smaller multipliers first.
> 
> 
> 
> *data* _null_;
> 
> do i=*1* to *10000000*;
> 
> y=*0*;
> 
> do x=-*1*,*1*,*0*,*.A*,*.Z*;
> 
> z=coalesce(*.*,divide(x,y));
> 
> end;
> 
> y=*2500*;
> 
> x=*5000*;
> 
> z=coalesce(*.*,divide(x,y));
> 
> end;
> 
> *run*;
> 
> 
> 
> Regards,
> 
> Mark
> 
> *From:* SAS(r) Discussion <SAS-L@LISTSERV.UGA.EDU> *On Behalf Of *Jean-Claude
> RAY
> *Sent:* Thursday, June 1, 2023 6:43 PM
> *To:* SAS-L@LISTSERV.UGA.EDU
> *Subject:* Re: DIVIDE function results
> 
> 
> 
> Hi Carl,
> 
> Unfortunately the "Z= IFN(Y=0,.,X/Y);" formula you suggest results in
> "Division by zero detected" for some values.
> 
> It is the case, for example, for the first 3 observations of the second
> dataset Nat Wooding used in his Saturday, April 29, 2023 8:01 AM message on
> this subject:
> 
> data Bruce;
> input  x   y ;
> cards;
> 1  0
> -1  0
> 0  0
> .A  0
> .Z  0
> 5000  2500
> ;
> 
> Because you mentioned "I have no idea if it might be faster or
> slower" I decided to compare, in terms of processing duration,
> the various formulas suggested, through this thread, by Nat Wooding, Mark
> Keintz, data _null_ and Yinglin Wu.
> 
> Because "real time" does vary across trials, I submitted 1000 times
> the same code for each formula (on my personal computer, without other
> current tasks).
> 
> That code was:
> data _null_;
> set Bruce;
> Z = formula ;
> run;
> 
> For each formula I got a (strangely never gaussian. Why?) distribution.
> 
> I used proc ttest to compare the "real time" means for each pair of
> these distributions.
> 
> The differences in efficiency are rather small, but statistically
> significant, between the four formulas.
> 
> The efficiency ranking is as follows:
> 
> 1)   Z = dividE((y ne 0)*x, y)  is the most efficient formula, with
> a "real time" mean equal to 0.0174 seconds
> 2)   Z = coalesce(. ,divide(X,Y))  follows immediately: "real time"
> mean = 0.0179 seconds
> 3)   Z = min (divide (X,Y) )  results in a "real time" mean = 0.0182
> seconds
> 4)   Z = min (. , divide (X,Y) )  lags a bit behind, with a "real
> time" mean = 0.0211 seconds.
> 
> Best,
> 
> Jean-Claude
> 
> 
> 
> 
> 
> 
> Le 31/05/2023 à 18:28, Carl Denney a écrit :
> 
> Another possibility could be
> 
> Z= IFN(Y=0,.,X/Y);
> 
> I have no idea if it might be faster or slower.
> 
> 
> 
> 
> 
> On 5/29/2023 2:42 PM, Yinglin (Max) Wu wrote:
> 
> Or just use the trick: divid((y ne 0)*x, y)
> 
> 
> 
> On Mon, May 29, 2023 at 3:37 PM Yinglin (Max) Wu <yinglinwu@gmail.com>
> wrote:
> 
> I am not having access to sas. But maybe coalesce(divid, .) could work?
> 
> 
> 
> On Fri, Apr 28, 2023 at 3:50 PM Bruce Gilsen <
> 000011e0fa56308e-dmarc-request@listserv.uga.edu> wrote:
> 
> I return periodically to the issue of avoiding divide by zero in the DATA
> step because it slows down execution a good deal.  Traditionally I
> recommend testing the denominator and:
> 1. if the denominator is 0, set the result to missing
> 2. otherwise, do the divide
> This returns the same result as brute force dividing, which sets the
> result to missing if the denominator is zero, but much more slowly.
> 
> The DIVIDE function works as quickly as checking the denominator as
> above.  It has simpler syntax: result=DIVIDE(numerator, denominator)
> instead of an IF/THEN/ELSE statement.
> But, it doesn't always return the same result: instead of setting the
> result to the standard missing value (.) when the denominator is zero, it
> does the following:
> 
> For Z = DIVIDE(X/Y), if Y is 0, then Z has the following values.
> 
> Value of X                                                      Value of Z
> Positive value                                                   .I
> Negative value                                                .M
> 0 or .
> .
> Any special numeric missing value         The value of X (e.g., if x=.M,
> Z=.M)
> 
> This is a real letdown for me.  Does anyone else wish that SAS would add
> an option to DIVIDE() that always returns . when the denominator is zero?
> 
> Bruce Gilsen
> speaking only for myself (and my fantasy baseball team which is in 3rd
> place of 12 early this year)
> 
> 
> 


[Attachment #3 (text/html)]

<div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace">I \
dare to say, my &quot;ifn ( Y ,   Divide (X,Y) , . )&quot; went the best ;-) ;-) \
;-)</div><div class="gmail_default" \
style="font-family:monospace,monospace"><br></div><div class="gmail_default" \
style="font-family:monospace,monospace">Bart</div><div class="gmail_default" \
style="font-family:monospace,monospace"><br></div><div class="gmail_default" \
style="font-family:monospace,monospace">Code:</div><div class="gmail_default" \
style="font-family:monospace,monospace"><br><font color="#0000ff">%macro \
test()/parmbuff;<br>data _null_;<br>   do i=1 to 1e8;<br>      y=0;<br>      do \
x=-1,1,0,.A,.Z;<br>         z=&amp;syspbuff.;<br>      end;<br>      y=2500;<br>      \
x=5000;<br>      z=&amp;syspbuff.;<br>   end;<br>run;<br><br>%mend \
test;<br><br><br><br>%test(.);<br>%test(dividE((y ne 0)*x, y));<br>%test(coalesce(. \
,divide(X,Y)));<br>%test(min (divide (X,Y) ));<br>%test( min (. , divide (X,Y) \
));<br>%test(ifn ( Y ,   Divide (X,Y) , . ))</font><br></div><div \
class="gmail_default" style="font-family:monospace,monospace"><br></div><div \
class="gmail_default" style="font-family:monospace,monospace">Log:</div><div \
class="gmail_default" style="font-family:monospace,monospace"><br></div><div \
class="gmail_default" style="font-family:monospace,monospace"><font \
color="#9900ff">1312    %macro test()/parmbuff;<br>1313    data _null_;<br>1314       \
do i=1 to 1e8;<br>1315          y=0;<br>1316          do x=-1,1,0,.A,.Z;<br>1317      \
z=&amp;syspbuff.;<br>1318          end;<br>1319          y=2500;<br>1320          \
x=5000;<br>1321          z=&amp;syspbuff.;<br>1322       end;<br>1323    \
run;<br>1324<br>1325    %mend test;<br>1326<br>1327<br>1328<br>1329    \
%test(.);<br><br>NOTE: DATA statement used (Total process time):<br>         <b>real \
time                1.01 seconds<br>         user cpu time          1.01 \
seconds</b><br>         system cpu time       0.00 seconds<br>         memory         \
318.31k<br>         OS Memory                27644.00k<br><br><br>1330    \
%test(dividE((y ne 0)*x, y));<br><br>NOTE: Missing values were generated as a result \
of performing an operation on missing values.<br>         Each place is given by: \
(Number of times) at (Line):(Column).<br>         200000000 at 1:17<br>NOTE: DATA \
statement used (Total process time):<br><b>         real time                5.49 \
seconds<br>         user cpu time          5.48 seconds</b><br>         system cpu \
time       0.00 seconds<br>         memory                     318.31k<br>         OS \
Memory                27644.00k<br><br><br>1331    %test(coalesce(. \
,divide(X,Y)));<br><br>NOTE: DATA statement used (Total process time):<br><b>         \
real time                4.44 seconds<br>         user cpu time          4.43 \
seconds</b><br>         system cpu time       0.00 seconds<br>         memory         \
318.31k<br>         OS Memory                27644.00k<br><br><br>1332    %test(min \
(divide (X,Y) ));<br><br>NOTE: Missing values were generated as a result of \
performing an operation on missing values.<br>         Each place is given by: \
(Number of times) at (Line):(Column).<br>         500000000 at 1:2<br>NOTE: DATA \
statement used (Total process time):<br>  <b>       real time                6.93 \
seconds<br>         user cpu time          6.93 seconds</b><br>         system cpu \
time       0.01 seconds<br>         memory                     318.31k<br>         OS \
Memory                27644.00k<br><br><br>1333    %test( min (. , divide (X,Y) \
));<br><br>NOTE: Missing values were generated as a result of performing an operation \
on missing values.<br>         Each place is given by: (Number of times) at \
(Line):(Column).<br>         500000000 at 1:3<br>NOTE: DATA statement used (Total \
process time):<br>  <b>       real time                6.91 seconds<br>         user \
cpu time          6.93 seconds</b><br>         system cpu time       0.04 seconds<br> \
memory                     318.31k<br>         OS Memory                \
27644.00k<br><br><br>1334    %test(ifn ( Y ,   Divide (X,Y) , . ))<br><br>NOTE: DATA \
statement used (Total process time):<br><b>         real time                4.29 \
seconds<br>         user cpu time          4.28 seconds</b><br>         system cpu \
time       0.03 seconds<br>         memory                     318.31k<br>         OS \
Memory                27644.00k<br></font><br></div><div class="gmail_default" \
style="font-family:monospace,monospace"><br></div></div><div \
id="DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br><table style="border-top:1px solid \
#d3d4de"><tr><td style="width:55px;padding-top:13px"><a \
href="http://www.avg.com/email-signature?utm_medium=email&amp;utm_source=link&amp;utm_campaign=sig-email&amp;utm_content=webmail" \
target="_blank"><img \
src="https://s-install.avcdn.net/ipm/preview/icons/icon-envelope-tick-green-avg-v1.png" \
alt="" width="46" height="29" style="width: 46px; height: 29px;"></a></td><td \
style="width:470px;padding-top:12px;color:#41424e;font-size:13px;font-family:Arial,Helvetica,sans-serif;line-height:18px">Virus-free.<a \
href="http://www.avg.com/email-signature?utm_medium=email&amp;utm_source=link&amp;utm_campaign=sig-email&amp;utm_content=webmail" \
target="_blank" style="color:#4453ea">www.avg.com</a></td></tr></table><a \
href="#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1"></a></div><br><div \
class="gmail_quote"><div dir="ltr" class="gmail_attr">pt., 2 cze 2023 o 03:35  Mark \
Keintz &lt;<a href="mailto:mkeintz@outlook.com">mkeintz@outlook.com</a>&gt; \
napisał(a):<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div \
class="msg-4096578250995838060">





<div lang="EN-US" style="overflow-wrap: break-word;">
<div class="m_-4096578250995838060WordSection1">
<p class="MsoNormal">Jean-Claude:<u></u><u></u></p>
<p class="MsoNormal"><u></u>  <u></u></p>
<p class="MsoNormal">I suspect you might get a better set of measures on comparative \
formula performance if dataset BRUCE were a lot larger.   Most of the time taken to \
process this sample data set (6 obs) probably was in compiling and setting up the \
data step,  which is not the component you want to measure.   Multiply the dataset \
size by some large multiplier.<u></u><u></u></p> <p class="MsoNormal"><u></u>  \
<u></u></p> <p class="MsoNormal">You could further de-confound the test.   Eliminate \
all the data input processing and embed the formulas in loops.   I used the same \
values as dataset BRUCE, with a multiplier of 10,000,000 for one of the formulas \
below.   The real time use  was 0.65 seconds.     I didn&#39;t know how fast it would \
be, so I tested with smaller multipliers first.<u></u><u></u></p> <p \
class="MsoNormal"><u></u>  <u></u></p> <p class="MsoNormal"><b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:navy;background:white">data</span></b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white"> </span><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:blue;background:white">_null_</span><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white">;<u></u><u></u></span></p> <p \
class="MsoNormal"><span style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white">   </span><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:blue;background:white">do</span><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white"> i=</span><b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:teal;background:white">1</span></b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white"> </span><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:blue;background:white">to</span><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white"> </span><b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:teal;background:white">10000000</span></b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white">;<u></u><u></u></span></p> <p \
class="MsoNormal"><span style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white">       y=</span><b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:teal;background:white">0</span></b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white">;<u></u><u></u></span></p> <p \
class="MsoNormal"><span style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white">       </span><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:blue;background:white">do</span><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white"> x=-</span><b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:teal;background:white">1</span></b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white">,</span><b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:teal;background:white">1</span></b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white">,</span><b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:teal;background:white">0</span></b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white">,</span><b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:teal;background:white">.A</span></b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white">,</span><b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:teal;background:white">.Z</span></b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white">;<u></u><u></u></span></p> <p \
class="MsoNormal"><span style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white">           z=coalesce(</span><b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:teal;background:white">.</span></b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white">,divide(x,y));<u></u><u></u></span></p> <p \
class="MsoNormal"><span style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white">       </span><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:blue;background:white">end</span><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white">;<u></u><u></u></span></p> <p \
class="MsoNormal"><span style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white">       y=</span><b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:teal;background:white">2500</span></b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white">;<u></u><u></u></span></p> <p \
class="MsoNormal"><span style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white">       x=</span><b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:teal;background:white">5000</span></b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white">;<u></u><u></u></span></p> <p \
class="MsoNormal"><span style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white">       z=coalesce(</span><b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:teal;background:white">.</span></b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white">,divide(x,y));<u></u><u></u></span></p> <p \
class="MsoNormal"><span style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white">   </span><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:blue;background:white">end</span><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white">;<u></u><u></u></span></p> <p \
class="MsoNormal"><b><span style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:navy;background:white">run</span></b><span \
style="font-size:12pt;font-family:&quot;Courier \
New&quot;;color:black;background:white">;</span><u></u><u></u></p> <p \
class="MsoNormal"><u></u>  <u></u></p> <p \
class="MsoNormal">Regards,<u></u><u></u></p> <p \
class="MsoNormal">Mark<u></u><u></u></p> <div>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt \
solid rgb(225,225,225);padding:3pt 0in 0in"> <p class="MsoNormal"><b>From:</b> SAS(r) \
Discussion &lt;<a href="mailto:SAS-L@LISTSERV.UGA.EDU" \
target="_blank">SAS-L@LISTSERV.UGA.EDU</a>&gt; <b>On Behalf Of </b>Jean-Claude \
RAY<br> <b>Sent:</b> Thursday, June 1, 2023 6:43 PM<br>
<b>To:</b> <a href="mailto:SAS-L@LISTSERV.UGA.EDU" \
target="_blank">SAS-L@LISTSERV.UGA.EDU</a><br> <b>Subject:</b> Re: DIVIDE function \
results<u></u><u></u></p> </div>
</div>
<p class="MsoNormal"><u></u>  <u></u></p>
<p class="MsoNormal" style="margin-bottom:12pt">Hi Carl,<br>
<br>
       Unfortunately the &quot;Z= IFN(Y=0,.,X/Y);&quot; formula you suggest results \
in &quot;Division by zero detected&quot; for some values.<br> <br>
It is the case, for example, for the first 3 observations of the second dataset Nat \
Wooding used in his Saturday, April 29, 2023 8:01 AM message on this subject:<br> \
<br> data Bruce;<br>
input   x     y ;   <br>
cards;<br>
1   0   <br>
-1   0   <br>
0   0     <br>
.A   0     <br>
.Z   0     <br>
5000   2500<br>
;<br>
<br>
         Because you mentioned &quot;I have no idea if it might be faster or \
slower&quot; I decided to compare, in terms of processing duration,<br> the various \
formulas suggested, through this thread, by Nat Wooding, Mark Keintz, data _null_ and \
Yinglin Wu.<br> <br>
      Because &quot;real time&quot; does vary across trials, I submitted 1000 times \
the same code for each formula (on my personal computer, without other current \
tasks).<br>  <br>
       That code was:     <br>
             data _null_;<br>
               set Bruce; <br>
              Z = formula ;   <br>
           run;<br>
<br>
      For each formula I got a (strangely never gaussian. Why?) distribution.<br>
<br>
         I used proc ttest to compare the &quot;real time&quot; means for each pair \
of these distributions.<br> <br>
       The differences in efficiency are rather small, but statistically significant, \
between the four formulas.<br>  <br>
       The efficiency ranking is as follows:<br>
<br>
           1)     Z = dividE((y ne 0)*x, y)   is the most efficient formula, with a \
                &quot;real time&quot; mean equal to 0.0174 seconds<br>
           2)    Z = coalesce(. ,divide(X,Y))   follows immediately: &quot;real \
                time&quot; mean = 0.0179 seconds<br>
           3)    Z = min (divide (X,Y) )   results in a &quot;real time&quot; mean = \
                0.0182 seconds<br>
           4)    Z = min (. , divide (X,Y) )   lags a bit behind, with a &quot;real \
time&quot; mean = 0.0211 seconds.<br> <br>
     Best,<br>
<br>
     Jean-Claude<br>
<br>
<br>
<br>
<br>
<br>
<br>
<u></u><u></u></p>
<div>
<p class="MsoNormal">Le 31/05/2023 à 18:28, Carl Denney a écrit  \
:<u></u><u></u></p> </div>
<blockquote style="margin-top:5pt;margin-bottom:5pt">
<p>Another possibility could be     <u></u><u></u></p>
<p>Z= IFN(Y=0,.,X/Y);<u></u><u></u></p>
<p>I have no idea if it might be faster or slower.<u></u><u></u></p>
<p><u></u>  <u></u></p>
<p><u></u>  <u></u></p>
<div>
<p class="MsoNormal">On 5/29/2023 2:42 PM, Yinglin (Max) Wu wrote:<u></u><u></u></p>
</div>
<blockquote style="margin-top:5pt;margin-bottom:5pt">
<div>
<p class="MsoNormal">Or just use the trick: divid((y ne 0)*x, y)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u>  <u></u></p>
<div>
<div>
<p class="MsoNormal">On Mon, May 29, 2023 at 3:37 PM Yinglin (Max) Wu &lt;<a \
href="mailto:yinglinwu@gmail.com" target="_blank">yinglinwu@gmail.com</a>&gt; \
wrote:<u></u><u></u></p> </div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt \
solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in"> \
<div> <p class="MsoNormal">I am not having access to sas. But maybe coalesce(divid, \
.) could work?<u></u><u></u></p> </div>
<div>
<p class="MsoNormal"><u></u>  <u></u></p>
<div>
<div>
<p class="MsoNormal">On Fri, Apr 28, 2023 at 3:50 PM Bruce Gilsen &lt;<a \
href="mailto:000011e0fa56308e-dmarc-request@listserv.uga.edu" \
target="_blank">000011e0fa56308e-dmarc-request@listserv.uga.edu</a>&gt; \
wrote:<u></u><u></u></p> </div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt \
solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in"> \
<p class="MsoNormal">I return periodically to the issue of avoiding divide by zero in \
the DATA step because it slows down execution a good deal.   Traditionally I \
recommend testing the denominator and:<br> 1. if the denominator is 0, set the result \
to missing<br> 2. otherwise, do the divide<br>
This returns the same result as brute force dividing, which sets the result to \
missing if the denominator is zero, but much more slowly.<br> <br>
The DIVIDE function works as quickly as checking the denominator as above.   It has \
simpler syntax: result=DIVIDE(numerator, denominator) instead of an IF/THEN/ELSE \
statement.   <br>
But, it doesn&#39;t always return the same result: instead of setting the result to \
the standard missing value (.) when the denominator is zero, it does the \
following:<br> <br>
For Z = DIVIDE(X/Y), if Y is 0, then Z has the following values.<br>
<br>
Value of X                                                                            \
Value of Z<br> Positive value                                                         \
.I<br> Negative value                                                                 \
.M<br> 0 or .                                                                         \
.<br> Any special numeric missing value              The value of X (e.g., if x=.M, \
Z=.M)<br> <br>
This is a real letdown for me.   Does anyone else wish that SAS would add an option \
to DIVIDE() that always returns . when the denominator is zero?<br> <br>
Bruce Gilsen<br>
speaking only for myself (and my fantasy baseball team which is in 3rd place of 12 \
early this year)<u></u><u></u></p> </blockquote>
</div>
</div>
</blockquote>
</div>
</div>
</blockquote>
</blockquote>
<p class="MsoNormal"><u></u>  <u></u></p>
</div>
</div>

</div></blockquote></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic