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

Hi,

 

I have created the following temporary "sorted" dataset. Would it be possible to provide me with code so that the variables within each observation are in ascending order (example output below)? Thanks!

 

Code

data sorted;

   input var1-var6;

   datalines;

     23 2 43 55 1 6

     132 3 23 67 45 2

     11 99 101 24 96 44

     44 1 1276 1734 1599 1921

     ;

run;

 

Output wanted

Obs  var1        var 2          var3        var4        var5        var6

1       1               2                6            23           43           55

2       2               3               23           45           67          132

3       1              24              44           96           99          101

4       1              44            1276       1599       1734       1921

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

CALL SORTN.

 

data sorted;

   input var1-var6;
  call sortn(of var1-var6);
[rest of your code] run;

@jeremy4 wrote:

Hi,

 

I have created the following temporary "sorted" dataset. Would it be possible to provide me with code so that the variables within each observation are in ascending order (example output below)? Thanks!

 

Code

data sorted;

   input var1-var6;

   datalines;

     23 2 43 55 1 6

     132 3 23 67 45 2

     11 99 101 24 96 44

     44 1 1276 1734 1599 1921

     ;

run;

 

Output wanted

Obs  var1        var 2          var3        var4        var5        var6

1       1               2                6            23           43           55

2       2               3               23           45           67          132

3       1              24              44           96           99          101

4       1              44            1276       1599       1734       1921


 

View solution in original post

2 REPLIES 2
Reeza
Super User

CALL SORTN.

 

data sorted;

   input var1-var6;
  call sortn(of var1-var6);
[rest of your code] run;

@jeremy4 wrote:

Hi,

 

I have created the following temporary "sorted" dataset. Would it be possible to provide me with code so that the variables within each observation are in ascending order (example output below)? Thanks!

 

Code

data sorted;

   input var1-var6;

   datalines;

     23 2 43 55 1 6

     132 3 23 67 45 2

     11 99 101 24 96 44

     44 1 1276 1734 1599 1921

     ;

run;

 

Output wanted

Obs  var1        var 2          var3        var4        var5        var6

1       1               2                6            23           43           55

2       2               3               23           45           67          132

3       1              24              44           96           99          101

4       1              44            1276       1599       1734       1921


 

jeremy4
Quartz | Level 8
Thanks a lot for your help!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 671 views
  • 0 likes
  • 2 in conversation