Date: Thu, 16 Oct 2003 09:37:19 -0400
Reply-To: "Chang Y. Chung" <chang_y_chung@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Chang Y. Chung" <chang_y_chung@HOTMAIL.COM>
Subject: Re: How many if-then-do in one Data Step?
Hi, Jim,
Yes. You are correct on speed. And thanks for the unrolled macro!
But one thing I am not quite sure if I agree with you. If you use a
constant on if condition, then wouldn't SAS compiler just optimize away
the if condition all together? Now I think of it, a logical expression
like a=1 may also be optimized. Maybe we should call a function instead,
like:
if ranuni(-1) > 1E-20 then do; /* which will be most likely to be true */
If it works, then I think we will be quite sure that there is no practical
limit on how deep you can nest the if-then-do-end construct in a data
step. Am i thinking correctly? I definately need a cup of coffee. :-)
Cheers,
Chang
On Thu, 16 Oct 2003 12:18:45 +0200, Groeneveld, Jim
<jim.groeneveld@VITATRON.COM> wrote:
>Hi Chang,
>
>Your code even runs fine with 5000 iterations or nested levels. But it
takes a long time to run, because of all that nesting of macro calls as
well. And actually that is what you test along that way. So I have tried
some other code (below), which only tests the nesting level of IF-DO's,
not of macro calls. I have tested this up to a depth of at least 66000,
which appeared to run OK, and quicker. I didn't test deeper, couldn't keep
my breath longer [;-)
>
>%MACRO Nesting (Looping);
>data _null_;
> %DO I = 1 %TO &Looping;
> if &I then do;
> put "&I";
> %END;
> %DO I = 1 %TO &Looping;
> end;
> %END;
>run;
>%MEND Nesting;
>
>%Nesting (66000);
>
>Regards - Jim.
>--
>. . . . . . . . . . . . . . . .
>
>Jim Groeneveld, MSc.
>Biostatistician
>Science Team
>Vitatron B.V.
>Meander 1051
>6825 MJ Arnhem
>Tel: +31/0 26 376 7365
>Fax: +31/0 26 376 7305
>Jim.Groeneveld@Vitatron.com
>www.vitatron.com
>
>I wish I had a webcam to show you the boring view from my window.
>
>[common disclaimer]
>
>-----Original Message-----
>From: Chang Y. Chung [mailto:chang_y_chung@HOTMAIL.COM]
>Sent: Wednesday, October 15, 2003 17:43
>To: SAS-L@LISTSERV.UGA.EDU; Groeneveld, Jim
>Subject: Re: How many if-then-do in one Data Step?
>
>
>On Wed, 15 Oct 2003 17:06:15 +0200, Groeneveld, Jim
><jim.groeneveld@VITATRON.COM> wrote:
>
>>Hi Kingsley,
>>
>>Are those IT-THEN-DO-END-ELSE-and-so-on-whatever blocks nested among each
>other? I faintly remember some arbitrary limit of around 147 for those a
>few years ago in vs. 6.12 4W.
>
>Hi, Jim,
>Is it true with R8? I have tested with my R8.2 on WINXP using the
>following. I was able to get a data step executed with 500 nested if-them-
>do-end's as shown in the below. Or my testing routine is inappropriate?
>Cheers,
>Chang
>SAS-----------------------------------------------------------------------
>%macro testIf(n);
> %if &n>0 %then %do;
> if cond then do;
> nIf + 1;
> %testIf(%eval(&n-1))
> end;
> %end; %else %do;
> put nIf=;
> %end;
>%mend testIf;
>
>data one;
> cond = 1;
> %testIf(500);
>run;
>/* log
>nIf=500
>NOTE: The data set WORK.ONE has 1 observations and 2 variables.
>NOTE: DATA statement used:
> real time 9.64 seconds
> cpu time 9.31 seconds
>*/
>--------------------------------------------------------------------------
|