Hi Guys
I have huge datasets in a library so i want extract last 5 observations for each dataset in a library
@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.
And what do you want to do with those 5 obervations?
See here: https://communities.sas.com/t5/SAS-Programming/last-three-obs/m-p/599976 and here: https://communities.sas.com/t5/SAS-Programming/multiple-table-extract-last-obs/m-p/616552
All found in your own(!) questions.
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;
@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.
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 25. 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.