Try this code:-
data second_dataset;
set sashelp.shoes nobs=the_count;
if _N_ > the_count -50;
run;
First find the number of observations in the data set, put it into a macro variable called NOBS.
Then
data want;
set have(firstobs=%eval(&nobs-49));
run;
Note that FIRSTOBS= option expects an integer larger than 0.
So if you would need a little more logic to get it right.
Something like:
%let nobs=19;
%let n=10;
%let firstobs=%sysfunc(max(1,&nobs-&n+1));
%put &=nobs &=n &=firstobs;
data want;
set sashelp.class(firstobs=&firstobs);
run;
Try this code:-
data second_dataset;
set sashelp.shoes nobs=the_count;
if _N_ > the_count -50;
run;
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.