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

How to find variables and observation count for each dataset in a Library

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

You can get this information from the SAS dictionary table dictionary.tables. Below an examples for library WORK.

IF there could be any ds in-place delete (i.e. using Proc SQL or data step modify statement) then note that rows don't get deleted physically but only logically. The logically deleted rows get only removed if the table gets physically re-created.

In below example investigate the values in nobs, delobs and nlobs.

data work.class;
  set sashelp.class;
run;

proc sql;
  delete from work.class
  where name='Alfred'
  ;
quit;

proc sql;
  select 
    libname,
    memname,
    nvar,
    nobs,
    delobs,
    nlobs
  from dictionary.tables
  where 
    libname='WORK' 
/*    and memname='CLASS'*/
  ;
quit;

Also: You will get obs counts from libraries pointing to SAS files. Libraries pointing to databases will show missings for nobs/delobs/nlobs. 

Databases don't maintain the number of rows in a table as metadata but you need to issue a select count(*) against the table to retrieve such information.

 

Below code will write to the SAS log what columns/information are available in dictionary.tables

proc sql;
  describe table dictionary.tables;
quit;

View solution in original post

3 REPLIES 3
sbxkoenk
SAS Super FREQ

Hello,

 

Use the dictionary tables and go on from there. 

Do something like:

PROC SQL noprint;
 create table abc as
 select *
 from dictionary.columns
 where LIBNAME='MYLIB';
QUIT;
PROC SQL noprint;
 create table def as
 select *
 from dictionary.tables
 where LIBNAME='MYLIB';
QUIT;

Cheers,

Koen

 

japelin
Rhodochrosite | Level 12

try this.

data want;
  set sashelp.vtable;
  where libname='XXX' and typemem='DATA';/* specify your libname in XXX */
  keep memname nobs nvar;
run;
Patrick
Opal | Level 21

You can get this information from the SAS dictionary table dictionary.tables. Below an examples for library WORK.

IF there could be any ds in-place delete (i.e. using Proc SQL or data step modify statement) then note that rows don't get deleted physically but only logically. The logically deleted rows get only removed if the table gets physically re-created.

In below example investigate the values in nobs, delobs and nlobs.

data work.class;
  set sashelp.class;
run;

proc sql;
  delete from work.class
  where name='Alfred'
  ;
quit;

proc sql;
  select 
    libname,
    memname,
    nvar,
    nobs,
    delobs,
    nlobs
  from dictionary.tables
  where 
    libname='WORK' 
/*    and memname='CLASS'*/
  ;
quit;

Also: You will get obs counts from libraries pointing to SAS files. Libraries pointing to databases will show missings for nobs/delobs/nlobs. 

Databases don't maintain the number of rows in a table as metadata but you need to issue a select count(*) against the table to retrieve such information.

 

Below code will write to the SAS log what columns/information are available in dictionary.tables

proc sql;
  describe table dictionary.tables;
quit;

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!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 2016 views
  • 0 likes
  • 4 in conversation