BookmarkSubscribeRSS Feed
🔒 This topic is locked. We are no longer accepting replies to this topic. Need further help? Please sign in and ask a new question.
SAS_Tipster
Moderator

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);
run;
/* 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 Using SAS Variable Lists Effectively |Schreier (2011).



Thanks to chang_y_chung for sharing this tip on sasCommunity.org.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Visit a random SAS tip This SAS Tips board is not open for replies or comments, but we welcome your feedback and questions. Have a question or comment about this tip? Start a new topic in one of our discussion boards, and reference this tip topic.
Discussion stats
  • 0 replies
  • 5190 views
  • 1 like
  • 1 in conversation