I have a data set of 6 numbers:
F1 F2 F3 F4 F5 F6
72 35 108 61 7 201
with over 1 million records.
I need each row to be ordered as below.
F1 F2 F3 F4 F5 F6
7 35 61 72 108 201
I have worked out how to do it in a macro and a very ugly data set using arrays. Is there an easyier way to do this?
Thanks again all.
Use the call sortn() function.
Here is a working example
data have;
length f1 - f6 8;
input f1 f2 f3 f4 f5 f6;
datalines;
72 35 108 61 7 201
;
run;
data want;
set have;
array fs (*) _numeric_;
call sortn(of fs(*));
run;
i think you just want to use the CALL SORTN() function.
data have;
input f1-f6 ;
cards;
72 35 108 61 7 201
;
data want ;
set have ;
call sortn(of f1-f6);
run;
data _null_;
set want;
put (_all_) (=);
run;
A very easy way within a DATA step:
call sortn(f1, f2, f3, f4, f5, f6);
There might be abbreviations available ... you could test either of these:
call sortn(of f1-f6);
call sortn(f1-f6);
One of those is pretty sure to work.
Looks like Tom is a little quicker than I am today!
Use the call sortn() function.
Here is a working example
data have;
length f1 - f6 8;
input f1 f2 f3 f4 f5 f6;
datalines;
72 35 108 61 7 201
;
run;
data want;
set have;
array fs (*) _numeric_;
call sortn(of fs(*));
run;
This was 3 times faster than my macro and 2 times faster than my ugly data step.
Thank you SO much!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.