Editor's note: this is a very popular question. To help others to find the answer, we have consolidated the most helpful answers into this one reply as an Accepted Solution.
or ...
/* Simple approach */
data last;
/* get number of records (N) */
if 0 then
set sashelp.class nobs=nobs end=eof;
/* use POINT= to get nth record */
set sashelp.class point=nobs;
output;
stop;
run;
More robust approach from @data_null__:
/* Create sample data */
data class;
set sashelp.class;
run;
data class;
modify class end=eof;
/* uncomment this to create empty set for test */
*remove;
if eof or ranuni(12344) lt .2 then
remove;
run;
/* print all records */
proc print;
run;
/* find last record, handle empty sets */
data last;
if eof then
stop;
do _n_ = nobs to 1 by -1 until(_error_ eq 0);
_error_ = 0;
set class point=_n_ nobs=nobs;
_obs_ = _n_;
end;
if _error_ eq 0 then
output;
stop;
set class(drop=_all_) end=eof;
run;
/* print last record */
proc print;
run;
... View more