Hello everyone,
I have a large dataset I don't know how many rows it has. I want its last 10 obs. Can I to do it in one data step?
Data want; set bigdata(firstobs=max-9); run;
Thanks!
data want;
do p=max(1,nobs-9) to nobs;
set bigdata nobs=nobs point=p;
output;
end;
stop;
run;
data want;
do p=max(1,nobs-9) to nobs;
set bigdata nobs=nobs point=p;
output;
end;
stop;
run;
data want;
set sashelp.class nobs=nobs;
if _n_>nobs-10;
run;
Better solution is to figure out the total number of observations in your data using proc contents. Then in proc print use firstobs=number of obs - 10 instead of obs=10.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.