BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BrahmanandaRao
Lapis Lazuli | Level 10

Hi Guys

I have huge datasets in a library so i want extract last 5 observations for each dataset in a library 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

@singhsahab with large datasets, you should use the POINT option:

data &&data&i;
do pt = nobs - 4 to nobs;
  set yrlibname.&&data&i nobs=nobs point=pt;
  output;
end;
stop;
run;

as that avoids reading the whole dataset.

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

And what do you want to do with those 5 obervations?

singhsahab
Lapis Lazuli | Level 10
proc sql;
select count(*) into :co from dictionary.tables where libname like 'yrlibname';
select memname into :data1 - :data%left(%trim(&co)) from dictionary.tables where libname like 'yrlibname';
quit;

%macro data_extract;
%do i=1 %to &co;
data &&data&i;
set yrlibname.&&data&i nobs=nobs;
if _n_ > nobs - 5;
run;
%end;
%mend;

%data_extract;
Kurt_Bremser
Super User

@singhsahab with large datasets, you should use the POINT option:

data &&data&i;
do pt = nobs - 4 to nobs;
  set yrlibname.&&data&i nobs=nobs point=pt;
  output;
end;
stop;
run;

as that avoids reading the whole dataset.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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 lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1540 views
  • 9 likes
  • 4 in conversation