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.
SSH2
Obsidian | Level 7

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

5 REPLIES 5
MarkWik
Quartz | Level 8

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

Reeza
Super User

Are these SAS data sets?

 

If so use SASHELP.VTABLE.

 

data want;
set sashelp.vtable;
where libname='WORK';
keep libname memname nobs;
run;
SSH2
Obsidian | Level 7
Thank you very much Reeza!
ballardw
Super User

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;

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