tags:

views:

313

answers:

3

I know that Sas starts with the observation at the top of a dataset when processing and proceeds to the next until it reaches the bottom observation, but is there an easy way to make sas process the bottom observation first and then work its way to the top?

+3  A: 

You certainly can change your data to be in reverse order, then process top down. Add a variable to the data set which acts as an index..then sort the data set descending by that variable.

data work.myData ;
 set work.myData ;
 indx = _n_ ;
run ;

proc sort data=work.myData ;
 by descending indx ;
run ;
CarolinaJay65
+1 for a version which works with views as well as data sets
Simon Nickerson
+5  A: 

You can use nobs and point to process it backwards without having to do any intermediate steps. Here's an example:

data backwards;
  do k= nobs to 1 by -1;
   set sashelp.class nobs = nobs point=k;
   output;
  end;
  stop;
run;
proc print data=sashelp.class;run;
proc print data=backwards;run;

See page 2 of this pdf for all the juicy details.

cmjohns
Nice tip and link
CarolinaJay65
A: 

Thank you both.

These are exactly what I needed.

They worked great.