DATA Step, Macro, Functions and more

Ordering without sorting

Accepted Solution Solved
Reply
Contributor
Posts: 43
Accepted Solution

Ordering without sorting

Hi,

 

Is there a way to move the observations as shown below without using the sort option?

 

 

data dataset;

length Segment $13;

input Segment var1 var2 var3;

datalines;

%_of_missing 19 23 12

0 32 43 23

1-10 23 534 343

11-20 434 432 42

21-30 23 123 543

31-40 443 2342 4234

41-50 32 25243 4523

51-100 324 5234 324

;

run;

 

data want;

length Segment $13;

input Segment var1 var2 var3;

datalines;

0 32 43 23

1-10 23 534 343

11-20 434 432 42

21-30 23 123 543

31-40 443 2342 4234

41-50 32 25243 4523

51-100 324 5234 324

%_of_missing 19 23 12

;

run;

proc print data=dataset;

run;

proc print data=want;

run;

 

 


Accepted Solutions
Solution
‎06-26-2017 09:21 AM
Super User
Posts: 5,504

Re: Ordering without sorting

Posted in reply to Data_User

Given that you just want to move the first observation to the end of the data set, this should work:

 

data want;

set have (firstobs=2) have (obs=1);

run;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,917

Re: Ordering without sorting

Posted in reply to Data_User

Unless I am missing something, your code does exactly what you asked for, it moves the line that begins %_of_missing to the bottom of the data set.

Super User
Posts: 7,782

Re: Ordering without sorting

Posted in reply to Data_User

- how do you identify the observation that has to be moved?

- how do you determine the position in which the observation should end up (beginning, end, after another defined obs, a given obs number, ...)?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 43

Re: Ordering without sorting

Posted in reply to KurtBremser

I just wanted to move 1st obs to the last obs. It's working as i expected from the below solution provided by @Astounding. Thanks for your efforts too.

Solution
‎06-26-2017 09:21 AM
Super User
Posts: 5,504

Re: Ordering without sorting

Posted in reply to Data_User

Given that you just want to move the first observation to the end of the data set, this should work:

 

data want;

set have (firstobs=2) have (obs=1);

run;

Contributor
Posts: 43

Re: Ordering without sorting

Posted in reply to Astounding

Awesome, this is what I wanted. Thanks a lot for your contribution.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 168 views
  • 3 likes
  • 4 in conversation