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!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 428 views
  • 0 likes
  • 2 in conversation