As the first step in the decommissioning of the site has been converted to read-only mode.

Here are some tips for How to share your SAS knowledge with your professional network.

Tips:Sorting an Array in Descending Order

From sasCommunity
Jump to: navigation, search

Call routines SORTN and SORTC can order an array in ascending order only. What if you want to order it in descending order? Here is an easy way!

  data _null_;
    array arr[*] v1-v5 (1 2 3 4 5);
    put "before:" (v1-v5) (= +1);
    /* reverse the variable list in a new array definition and sort */
    array rev[*] v5-v1;
    call sortn(of rev[*]);
    put "after :" (v1-v5) (= +1);
  /* on log
  before: v1=1  v2=2  v3=3  v4=4  v5=5
  after : v1=5  v2=4  v3=3  v4=2  v5=1

For a detailed discussion on variable lists, see Schreier (2011).

Submitted By chang_y_chung