Date: Mon, 13 Jul 1998 21:49:37 +0100
Reply-To: "Andrew J. L. Cary" <ajlcary@CARYCONSULTING.COM>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: "Andrew J. L. Cary" <ajlcary@CARYCONSULTING.COM>
Subject: Re: Recursion in SAS macro language, reality or uthopia ?
It is a little unclear to me why recursion is necessary here for a couple of
reasons:
(1) With the example shown a simple %DO I=1 %TO &P ;...%END; would
meet purposes better. Using recursion to perform iterative processing
seems to be an unneccessarily complex methodology when a set of native
iterative statements are built into the macro language.
BTW. The computation of factorials in the macro language
is best accomplished using %LET N = %SYSFUNC(GAMMA(P-1)) ;
(2) The macro language is really intended as a SAS code generator. The
DATA step and PROC IML are much better suited for computation then the
MACRO language. Maybe I'm just being a mossback here, but I think that you
might want to rethink your approach to move the computation and calculation
into the SAS layer rather then the macro layer. I have run quite large and
complex
simulations and analyses using no macros (though macros do make it easier)
(3) As I recollect, each instantiation of a SAS macro grabs a 32 KB memory
buffer to store compiled macro code and local variables in. This memory is
released
when each macro closes. By recursively executing a macro each instance will
grab
yet another 32KB chunk. Since in recursion no macro has yet closed no space
will
be released until the macro has reached a stopping point and recursed back
up the
tree. 46 iterations works out to 1.51MB (46*32KB). You simply may be
running into
quota limits. BTW I get 47 under Windows NT 4.0;
-----------------------------------------------------------
Andrew J.L. Cary
Chief Curmudgeon
Cary Consulting Systems
http://www.caryconsulting.com
Rodney Sparapani wrote in message <35AA60FA.B84DF501@duke.edu>...
>Fabrizio:
>
>Can you re-formulate the problem so that multiple SAS jobs operate on the
problem
>instead of doing all of the recursion with the macro language? I've used
>recursion in SAS macros for permutations and combinations, but never 46
levels.
>
>Rodney
>
>Fabrizio Carinci wrote:
>
>> Hi SAS-Lers,
>> here is a program addressed in the past on SAS-L but apparently remained
>> unsolved (as far as I know).
>>
>> Recursion is a programming technique not always suggested,
>> but sometimes necessary for statistical and numerical
>> analysis reasons.
>>
>> In my case, I'm writing some code to perform calculations for
>> likelihood cross-validation in the case of a COX PH discrete logistic
>> model. More precisely, I need to implement the technique used by PROC
>> PHREG for TIES=DISCRETE which has been originally published by Gail et
>> al., 1983 (referenced in SAS/STAT manual up to v. 6.11).
>>
>> Unfortunately, my SAS program aborted with the infamous error
>> message "Maximum source manager level number exceeded. The nesting of
>> %INCLUDE files, or macros, or both, is too deep".
>>
>> As an example, one can keep the following macro and look
>> what happens:
>>
>> =================
>>
>> %let p=0;
>>
>> %MACRO TECCHIO;
>> %let p=%eval(&p+1);
>> %put LOOP No.&P DONE;
>> %TECCHIO;
>> %MEND TECCHIO;
>>
>> %TECCHIO;
>>
>> =================
>>
>> At the 46th loop on our AXP Digital machine it ends with the error
>> message. I also noticed that the magical number is 47 on a SUN machine.
>> (????).
>>
>> Since one usually need unlimited looping (today datasets come from very
>> large databases), the lack of a recursion application of SAS macro
>> language seems to me a major fault.
>>
>> Moreover, in our case we must write down all the recursive formula and
>> at the end perform the final calculation, which means that I can't work
>> with DATASTEPS or IML.
>>
>> Any hints will be appreciated.
>> Thanks in advance.
>> Fabrizio
>>
>>
===========================================================================
===
>> Fabrizio Carinci, Statistician
>> Head, Unit of Statistics and Information Systems,
>> Department of Clinical Pharmacology and Epidemiology
>> Consorzio Mario Negri Sud, Strada Nazionale-66030 S.Maria Imbaro
(Chieti)-ITALY
>> Web: http://www.cmns.mnegri.it
>> -------------------------------------------------------------------------
------
>> TEL: 39-872-570265 FAX: 39-872-578240 E-MAIL:
carinci@cmns.mnegri.it
>>
===========================================================================
===
>
>
>
|