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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: