|
At 20:16 25/04/98 GMT, Henry Voyer wrote:
>I have an array like
>c1 =0; c2 =0; c3 = 0; c4 = 0;
>array client(5) c0-c4;
>after i add some random values
>il like it to sort so that
>c1 to c4 has from lesser to greater.
Henry, the simplest thing to do is to copy the array elements into a second
array, using the ORDINAL function to transfer them in sorted order:
data try (drop = i ) ;
array c(*) c0 - c4 ;
c0 = 5 ; c1 = 10 ; c2 = 3 ; c3 = 1 ; c4 = 8 ;
array x(*) x0 - x4 ;
do i = 1 to dim(x) ;
x(i) = ordinal(i, of c0-c4 ) ;
end ;
run ;
If you want to get them back into the original array, and delete the second
array you used for the sorting, then add a little to the code, like:
data try (drop = i x0-x4 ) ;
array c(*) c0 - c4 ;
c0 = 5 ; c1 = 10 ; c2 = 3 ; c3 = 1 ; c4 = 8 ;
array x(*) x0 - x4 ;
do i = 1 to dim(x) ;
x(i) = ordinal(i, of c0-c4 ) ;
end ;
do i = 1 to dim(x) ; c(i) = x(i) ; end ;
run ;
Is that any help?
Regards,
John
----------------------------------------------------------------
Dr John Whittington, Voice: +44 (0) 1296 730225
Mediscience Services Fax: +44 (0) 1296 738893
Twyford Manor, Twyford, E-mail: medisci@powernet.com
Buckingham MK18 4EL, UK mediscience@compuserve.com
----------------------------------------------------------------
|