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 (July 1998, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 14 Jul 1998 19:38:19 GMT
Reply-To:     Andreas Grueninger <grueni@STUTTGART.NETSURF.DE>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         Andreas Grueninger <grueni@STUTTGART.NETSURF.DE>
Organization: LF.net GmbH, Internet Services, Stuttgart, Germany
Subject:      Re: Modular recursion in COBOL and SAS (was: Re:Recursion in
              SAS-the exact query)

Hmm,

very nice discussion about english grammar. I appreciate this very much to improve my knowledge about the english language (I am german). Back to SAS: Paul, do you really think this is recursion if you go to the label? I guess it is something like a restart of the do loops. If it would be a real recursion the value i should be restored if the recursive called function (here a link/return or for the COBOL freaks a perform) is finished. This is not the case. The values of the index i after the LINK part in the do loop starts with the last value of i before the last jumping out and is incremented by 1 for each RETURN. This is somewhat bizzare and IMHO good for nothing. I changed the code a little bit to show the values of a new variable x and the index i.

BTW: And for Aston Lexmart (the C and Assembler freak): Real recursion can be done easily in SAS with SCL and calling of methods. So it would be easy to implement a quicksort. The more intelligent solution would be to use proc sort.

DATA _NULL_; ARRAY A(9) (4,7,3,1,9,6,2,8,5); KEY = 1; PIVOT = 9; STEP = -1; x = 0; IF 0 THEN DO; PART: DO J=1 TO 9; PUT A(J) @; END; PUT; *SHOW CURRENT STATE OF ARRAY; DO I = PIVOT TO KEY BY STEP; IF STEP * (A(I) - A(KEY)) > 0 THEN DO; T=A(I); A(I)=A(KEY); A(KEY)=T; *SWAP ELEMENTS; PIVOT = KEY - STEP; PUT key= @; KEY = I; STEP = (-1) * STEP; *SWAP SWEEP DIRECTION; x + 1; PUT i= x= @; LINK PART; *CALL ITSELF; PUT x= i=; END; END; RETURN; END; LINK PART; RUN; 4 7 3 1 9 6 2 8 5 KEY=1 I=7 X=1 2 7 3 1 9 6 4 8 5 KEY=7 I=2 X=2 2 4 3 1 9 6 7 8 5 KEY=2 I=4 X=3 2 1 3 4 9 6 7 8 5 X=3 I=5 X=3 I=6 X=3 I=7

--------------------------- Andreas Grueninger

PRIVAT: grueni@stuttgart.netsurf.de OFFICIAL: grueninger@lfl.bwl.de ---------------------------


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