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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.