|
> From: Ted Clay
> Subject: sorting arrays
>
> I am hoping to improve on the technique for sorting values
> within an array
> (in a data step), which I implement using a macro.
>
> Is there a call or other non-macro solution to do this?
This is a FAQ.
I have posted some of Donald Knuth's sorting and searching algorithms
written in SAS
Here is the sas community wiki page for Shell Sort:
http://www.sascommunity.org/wiki/Knuth_Shell_Sort
You can search the SAS-L archives near the 2002-August date to see the
other programs.
Ron Fehd the algorithm maven CDC Atlanta GA USA RJF2 at cdc dot gov
> Outputting the
> data and using proc sort is not an option.
>
> The program, whose purpose is to sort array B_ randomly,
> looks like this:
>
>
>
> Data testdata;
>
> Array a_ {*} a1-a7;
>
> Array b_ {*} b1-b7;
>
> Do i=1 to 7;
>
> A_(i)=ranuni(15151);
>
> B_(i)=I;
>
> End;
>
> Run;
>
>
>
> Data result;
>
> Set testdata;
>
> Array a_ {*} a1-a7;
>
> Array b_ {*} b1-b7;
>
> %sortaray(by=a_,others=b_);
>
> Run;
>
>
>
> proc print data=result;
>
> var b:;
>
> run;
>
>
>
> Produces .
>
>
>
>
> Obs b1 b2 b3 b4 b5 b6 b7
>
>
>
> 1 4 5 1 6 7 3 2
>
>
|