Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 372471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:12:50+00:00 2026-05-12T14:12:50+00:00

Is there a way to check how many observations are in a SAS data

  • 0

Is there a way to check how many observations are in a SAS data set at runtime OR to detect when you’ve reached the last observation in a DATA step?

I can’t seem to find anything on the web for this seemingly simple problem. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:12:50+00:00Added an answer on May 12, 2026 at 2:12 pm

    The nobs= option to a set statement can give you the number of observations. When the data step is compiled, the header portion of the input datasets are scanned, so you don’t even have to execute the set statement in order to get the number of observations. For instance, the following reports 2 as expected:

    /* a test data set with two observations and no vars */
    data two;
      output;
      output;
    run;
    
    data _null_;
      if 0 then set two nobs=nobs;
      put nobs=;
    run;
    /* on log
    nobs=2
    */
    

    The end= option sets a flag when the last observation (for the set statement) is read in.

    A SAS data set, however, can be a SAS data file or a SAS view. In the case of the latter, the number of observations may not be known either at compile time or at execution time.

    data subclass/view=subclass;
      set sashelp.class;
      where sex = symget("sex");
    run;
    
    %let sex=F;
    data girls;
      set subclass end=end nobs=nobs;
      put name= nobs= end=;
    run;
    /* on log
    Name=Alice nobs=9.0071993E15 end=0
    Name=Barbara nobs=9.0071993E15 end=0
    Name=Carol nobs=9.0071993E15 end=0
    Name=Jane nobs=9.0071993E15 end=0
    Name=Janet nobs=9.0071993E15 end=0
    Name=Joyce nobs=9.0071993E15 end=0
    Name=Judy nobs=9.0071993E15 end=0
    Name=Louise nobs=9.0071993E15 end=0
    Name=Mary nobs=9.0071993E15 end=1
    */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to check how many threads are waiting for a synchronized
Is there a simple way to check how many times a character appears in
is there a way to validate a form through JS and check how many
Is there a creative and easy way to check many form fields at once.
Is there any way to check whether a file is locked without using a
Is there a way to check if a file has been opened by ReWrite
Is there a way to check to see if a date/time is valid you
Is there any way to check if a given index of an array exists?
Is there a way to check how much a flash file is (down)loaded to
Is there a way to check if a ValidationSummary control has its IsValid property

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.