dimanche 29 mars 2020

How to get last two observations from a dataset in SAS without using sort or First. and Last. or Do loop

Below code will solve for getting last 2 observations from the dataset without using loops, first & last dot concept or sorting.

data a;
set sashelp.cars nobs=_nobs_;/*create the temporary variable to store total no of obs*/
if _N_ ge _nobs_-1;/*Now compare the automatic variable _N_ to _nobs_*/
run;

Aucun commentaire:

Enregistrer un commentaire