Use the point option directly access the last obs. The most efficient way. The stop is necessary here. Otherwise sas will run forever. Check the doc for more details.
the nobs option will provide the number of obs at compiling time.
proc print data=sashelp.class;
run;
data needed;
set sashelp.class nobs=nobs point=nobs;
output;
stop;
run;