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 (September 2007, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 18 Sep 2007 10:55:55 -0400
Reply-To:   "Fehd, Ronald J. (CDC/CCHIS/NCPHI)" <rjf2@CDC.GOV>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Fehd, Ronald J. (CDC/CCHIS/NCPHI)" <rjf2@CDC.GOV>
Subject:   Re: problem of insertion sorting algorithms
In-Reply-To:   <1190125088.055151.273370@19g2000hsx.googlegroups.com>
Content-Type:   text/plain; charset=us-ascii

> From: yangsky66 > /*insertion sort algorithm*/ > /* 1. For j = 2 to length [A] do > 2. key = A[j] > 3. comment {Put A[j] into the sorted sequence A[1 . . j-1] > 4. i = j -1 > 5. while i > 0 and A[i] > key do > 6. A[i+1] = A[i] > 7. i = i-1 > /* 8. A[i+1] = key*/

the above is pseudo code

your translation of line 5 to sas 'do while' is incorrect.

see:

tip Knuth sorting by insertion

http://www.listserv.uga.edu/cgi-bin/wa?A2=ind0208C&L=sas-l&P=R8711

Ron Fehd the macro maven CDC Atlanta GA USA RJF2 at cdc dot gov

> proc iml; > A={5 2 4 6 1 3 }; > do j=2 to 6; > key=A[j]; > i=j-1; > do while((i>0)&& (A[i]>key)); > A[i+1]=A[i]; > i=i-1; > end; > A[i+1]=key; > end; > print a; > quit; > > > I try to a simple insertion sorting algorithms. SAS tells me > DO while is wrong. I still could not get results even though > I change to do while (A[i]>key); A[i+1]=A[i]; i=i-1; if i<=1 > then stop; end; > > > Could anybody tells me where is wrong in my code? > Thank you a lot > >


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