SAS : Reverse Order of Data

This tutorial explains how to reverse order of data in SAS.
Reverse order of data

Create Sample Data
data temp;
input var1 @@;
cards;
2 9 6 4 3 8
;
run;

Method I : With Sorting
data temp2;
set temp;
i = _N_;
run;
proc sort data = temp2;
by descending i;
run;
Method II : Without Sorting
data temp2;
do i = nobs to 1 by -1;
set temp nobs = nobs point=i;
output;
end;
stop;
run;

  1. The POINT= option allows us to point to and select a given observation. 
  2. The NOBS= creates and names a temporary variable whose value is usually the total number of observations in the input data set or data sets. If more than one data set is listed in the SET statement, NOBS= the total number of observations in the data sets that are listed.

About Author:

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 8 years of experience in data science. During his tenure, he has worked with global clients in various domains like Banking, Insurance, Telecom and Human Resource.

Related Posts:
5 Responses to "SAS : Reverse Order of Data"
  1. Replies
    1. Because Point uses Direct Access Read Mode while reading input data set and hence it does not understand EOF marker which specifies end of file. If you do not specify STOP statement then the above program will go in infinite loop. To avoid that we use stop statement to explicitly specify end of input file.

      Hope this helps.

      Delete
  2. Can u explain more examples on this.
    tq

    ReplyDelete

We have Zero Tolerance to Spam. Comments with links will be deleted immediately upon our review.

Next → ← Prev
Love this Post? Spread the Word!
Share