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. 

SAS Innovate 2025: Call for Content

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 10496 views
  • 10 likes
  • 4 in conversation