|
> 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
>
>
|