SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Srigyan
Quartz | Level 8

 How to get the count of total records from all the tables in a library. I have one library with multiple datasets. I want to know what is the number of records in each of the tables. how can I do it?

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

If your data library points to a database -- not a folder of SAS data sets -- then NOBS might might not be available in the metadata that SAS can see.  Instead, you might need to use PROC SQL with COUNT(*) or issue a database-specific query using PROC SQL and the CONNECT clause.

 

Also, if the library is a folder of SAS files but they are VIEW type and not DATA, then you won't be able to see the record count in the metadata.

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!

View solution in original post

8 REPLIES 8
Srigyan
Quartz | Level 8

noobs is blank. is there any macro which can help.

Kurt_Bremser
Super User

@Srigyan wrote:

noobs is blank. is there any macro which can help.


"noobs" is an option for proc print. Read my post thoroughly.

Here is some code for reference:

data class;
set sashelp.class;
run;

data cars;
set sashelp.cars;
run;

proc sql;
select sum(nobs) as nobs from dictionary.tables where libname = 'WORK' and memtype = 'DATA';
select memname, nobs from dictionary.tables where libname = 'WORK';
quit;

Result:

                        nobs
                    --------
                         455
                                                

                                      Number of
                                       Physical
 Member Name                       Observations
 ----------------------------------------------
 CARS                                       428
 CLASS                                       19
 _PRODSAVAIL                                  8
Srigyan
Quartz | Level 8

some i am getting dots(.) in nobs, i am not getting any values.

Srigyan
Quartz | Level 8

proc sql;
select sum(nobs) as nobs from dictionary.tables where libname = 'G2NONPII' and memtype = 'DATA';
select memname, nobs from dictionary.tables where libname = 'G2NONPII';
quit;

 

its giving me 

TABLE NAMENobs
T1.
T2.
T3.
ChrisHemedinger
Community Manager

If your data library points to a database -- not a folder of SAS data sets -- then NOBS might might not be available in the metadata that SAS can see.  Instead, you might need to use PROC SQL with COUNT(*) or issue a database-specific query using PROC SQL and the CONNECT clause.

 

Also, if the library is a folder of SAS files but they are VIEW type and not DATA, then you won't be able to see the record count in the metadata.

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
RW9
Diamond | Level 26 RW9
Diamond | Level 26
proc sql;
  select sum(nobs) from sashelp.vtable where libname="YOURLIB";
quit;

Replace yourlib with your libname, and make sure its upper case.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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
  • 8 replies
  • 10203 views
  • 1 like
  • 4 in conversation