Hi,
As we all know that SAS processes the observation from dataset from top to bottom.
Suppose we have a situation where we want to process the bottom observation first from SAS dataset. We can not change the basic property of SAS system but we can change our SAS Dataset.
Which means, here we are changing the order of observations in SAS dataset. Our last observation would be first and the first one would get changed into last. In Simple words, just to reverse the order of observation of sas dataset.
Support we have a dataset, Named as DSN as follows :
Output would be as :
Here we would discuss the two ways to perform our task:
1. Just apply an index with observations and then sort the data in descending order.
The output would be as :
2. We can get the desired output by using data step only as well, with the help of NOBS and POINT
DATA DSN_REVR;
Do U=NOBS TO 1 by -1;
SET DSN NOBS=NOBS POINT= U;
OUTPUT;
END;
STOP;
RUN;
As we all know that SAS processes the observation from dataset from top to bottom.
Suppose we have a situation where we want to process the bottom observation first from SAS dataset. We can not change the basic property of SAS system but we can change our SAS Dataset.
Which means, here we are changing the order of observations in SAS dataset. Our last observation would be first and the first one would get changed into last. In Simple words, just to reverse the order of observation of sas dataset.
Support we have a dataset, Named as DSN as follows :
Data DSN;
Input Name $7.;
Cards;
Alfred
Barbara
Carol
Jane
Jeffrey
Louise
Philip
Robert
Thomas
William
Run;
Input Name $7.;
Cards;
Alfred
Barbara
Carol
Jane
Jeffrey
Louise
Philip
Robert
Thomas
William
Run;
Output would be as :
Here we would discuss the two ways to perform our task:
1. Just apply an index with observations and then sort the data in descending order.
DATA DSN;
SET DSN;
INX =_N_ ;
Run;
PROC SORT DATA=DSN OUT=DSN_REVR (KEEP=NAME) ;
BY DESCENDING INX ;
RUN;
The output would be as :
2. We can get the desired output by using data step only as well, with the help of NOBS and POINT
DATA DSN_REVR;
Do U=NOBS TO 1 by -1;
SET DSN NOBS=NOBS POINT= U;
OUTPUT;
END;
STOP;
RUN;