BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Lochdonan
Fluorite | Level 6

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.

1 ACCEPTED SOLUTION

Accepted Solutions
AhmedAl_Attar
Rhodochrosite | Level 12

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;

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

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;

 

Astounding
PROC Star

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!

 

AhmedAl_Attar
Rhodochrosite | Level 12

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;

Lochdonan
Fluorite | Level 6

This was 3 times faster than my macro and 2 times faster than my ugly data step.

Thank you SO much!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1137 views
  • 0 likes
  • 4 in conversation