LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (May 2007, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Mon, 28 May 2007 22:16:26 -0700
Reply-To:   David L Cassell <davidlcassell@MSN.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   David L Cassell <davidlcassell@MSN.COM>
Subject:   Re: Proc FCMP and recursion
In-Reply-To:   <200705252005.l4PHE0VT005134@mailgw.cc.uga.edu>
Content-Type:   text/plain; format=flowed

weiming.zhang@UCHSC.EDU wrote: > >Hi, > >I have been using Proc FCMP to do recursion. I found that it may modify the >variable in the caller. For instance, > >proc fcmp outlib=sasuser.funcs.math; > function fact(k); > if k = 1 then return(k); > put "pre K = " k; > z = k; *preserve k; > x = fact(k-1); > put "after k = " k; > k = z; *recover k; > k = k * x; > return(k); > endsub; >run;quit; > >options cmplib=sasuser.funcs; >proc fcmp; > x = fact(5); > put "x = " x; >run; > >it will not give correct answer if the two commented line are removed. Does >anyone know why? > >thanks. > >wz

I have not seen anything that indicates that the functions created in PROC FCMP will maintain their own local state independent of other simultaneous or recursive calls to the same function. Your code assumes that all such calls maintain their own state, as if this really were C.

You can see the effects if you use the PUT _PDV_ statement a few times inside your function. Note that this works in PROC FCMP but it will *NOT* work in a data step. In a data step, you could use PUT _ALL_ instead but the results will not be as nicely arranged.

HTH, David -- David L. Cassell mathematical statistician Design Pathways 3115 NW Norwood Pl. Corvallis OR 97330

_________________________________________________________________ Like the way Microsoft Office Outlook works? You’ll love Windows Live Hotmail. http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_outlook_0507


Back to: Top of message | Previous page | Main SAS-L page