Date: Wed, 8 Jul 1998 11:47:42 -0400
Reply-To: "Dorfman, Paul" <pdorfma@UCS.ATT.COM>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: "Dorfman, Paul" <pdorfma@UCS.ATT.COM>
Subject: Re: Recursion in SAS macro language, reality or utopia ?
Content-Type: text/plain
Replying to Gerald Zuckier, Jack Hamilton, in particular, wrote:
>There are undoubtedly problems that can be solved more easily using
>recursion than not using recursion, but find the factorial of a number
>is not such a problem. The non-recursive code for finding a factorial
>in SAS would be (assuming a positive or zero value for X):
>
> fact = 1;
> do i = 2 to x;
> fact = fact * i;
> end;
>
>I don't think you can make a convincing case that that's messier or
more
>unclear than the recursive version. It will almost certainly run
faster
>and use less memory.
In fact, infinitely faster, if to account for the fact that in the DATA
step, recursive function call is impossible to implement because of the
mere absence of user-defined functions. That is, the ones, for which
the compiler would maintain an internal stack to hold unresolved copies
of themselves, are not supported. So other than in the Macro Language,
finding factorial simply cannot be programmed the way Gerald implied,
and the iterative approach you demonstrated is the only one feasible.
>Hasn't someone proven that any problem which can be solved recursively
>can also be solved non-recursively?
Sure someone has.
Regards, Paul.
------------------------------
|