07-17-2014 05:50 PM
How to sort the values in a macro? For example, I have the following macro
%let macro1 = 15 77 22 40;
I want to create another macro having the same values in ¯o1 but with increasing order like
¯o2 = 15 22 40 77;
Thanks a lot!
07-17-2014 06:26 PM
Since your input is a string of numbers it seems that using a data step array is most logical and easiest to code. If you want it to be function style you could make a macro that uses DOSUBL. This would be the innards of such a function style macro.
23 %let macro1=15 77 44 8;
24 data _null_;
25 array t[%sysfunc(countw(¯o1,%str( )))] _temporary_ (¯o1);
26 call sortn(of t
27 call symputx('macro2',catx(' ',of t
29 %put &=macro2;
MACRO2=8 15 44 77