DATA Step, Macro, Functions and more

list all the datasets in a folder and number of observations in each dataset

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

list all the datasets in a folder and number of observations in each dataset

Hi,

I need to write a program to create a table with 2 columns. One column lists all the datasets names in a folder, one column lists the number of observations for the corresponding dataset.  Is there an easy way to do it? My code worked but it is looks not efficient and not neat enough.

Thank you.

 


Accepted Solutions
Solution
‎03-12-2018 12:56 PM
Super User
Posts: 13,066

Re: list all the datasets in a folder and number of observations in each dataset

Or similar to @Reeza's approach if looking for SAS datasets.

Proc sql;
   create table want as
   select memname, nobs
   from dictionary.tables 
   where libname='LIBRARY'
   ;
run;

The library name should be in uppercase as that is the way SAS stores the information.

 

If the folder doesn't currently have a library associated then run a libname statement pointing to that library before the Proc SQL.

 

I use the dictionary table version as I have a moderate number of permanently libraries and the SQL version runs notably faster than the datastep version for most tasks.

This will send the various things you may request from the dictionary.tables to the Log:

Proc sql;
   describe table dictionary.tables 
   ;
run;

View solution in original post


All Replies
Frequent Contributor
Posts: 99

Re: list all the datasets in a folder and number of observations in each dataset

Hi @SSH2  Can you please share your code that you deem inefficient? I think it's a good practice to eliminate duplicate redundancies to avoid somebody to come up with the same code you wrote. Thank you

Super User
Posts: 22,857

Re: list all the datasets in a folder and number of observations in each dataset

Are these SAS data sets?

 

If so use SASHELP.VTABLE.

 

data want;
set sashelp.vtable;
where libname='WORK';
keep libname memname nobs;
run;
Occasional Contributor
Posts: 12

Re: list all the datasets in a folder and number of observations in each dataset

Thank you very much Reeza!
Solution
‎03-12-2018 12:56 PM
Super User
Posts: 13,066

Re: list all the datasets in a folder and number of observations in each dataset

Or similar to @Reeza's approach if looking for SAS datasets.

Proc sql;
   create table want as
   select memname, nobs
   from dictionary.tables 
   where libname='LIBRARY'
   ;
run;

The library name should be in uppercase as that is the way SAS stores the information.

 

If the folder doesn't currently have a library associated then run a libname statement pointing to that library before the Proc SQL.

 

I use the dictionary table version as I have a moderate number of permanently libraries and the SQL version runs notably faster than the datastep version for most tasks.

This will send the various things you may request from the dictionary.tables to the Log:

Proc sql;
   describe table dictionary.tables 
   ;
run;
Occasional Contributor
Posts: 12

Re: list all the datasets in a folder and number of observations in each dataset

Thank you very much!!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 135 views
  • 1 like
  • 4 in conversation