Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Number of Observations in a SAS Dataset

Things under legendu.net/outdated are outdated technologies that the author does not plan to update any more. Please look for better alternatives.

** Things under legendu.net/outdated are outdated technologies that the author does not plan to update any more. Please look for better alternatives. **

proc sql;
    select count(*) from lib.dataset;
run;

Proc sql is not efficient when we have large dataset. Though using ATTRN is good method but this can accomplish within base sas, here is the efficient solution that can give number of obs of even billions of rows just by reading one row:

data DS1;
    set DS nobs=i;
    if _N_ =2 then stop;
    No_of_obs=i;
run;
data _null_;
    set yourdataset nobs=number;
    put number= ;
    stop;
run;