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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User
data want;
  do p=max(1,nobs-9) to nobs;
    set bigdata nobs=nobs point=p;
    output;
  end;
  stop;
run;

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User
data want;
  do p=max(1,nobs-9) to nobs;
    set bigdata nobs=nobs point=p;
    output;
  end;
  stop;
run;
Ksharp
Super User
data want;
 set sashelp.class nobs=nobs;
 if _n_>nobs-10;
run;
GeorgeSAS
Lapis Lazuli | Level 10
Thanks, this work on small data but it will take long time on big data
srikanth421
Calcite | Level 5

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. 

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
  • 13024 views
  • 12 likes
  • 4 in conversation