How can I read the filenames from a library into a dataset?
Thx,
Stefan
Hi,
Since you mentioned 'library' instead of a folder/directory, I would assume you are trying to put data set names into a data set, and then there is a simple way: say you want every table names within 'work':
proc sql;
create table want as
select distinct memname as dname from dictionary.columns where libname='WORK';
QUIT;
Haikuo
Hi,
Something similar was discussed in:
https://communities.sas.com/message/125021#125021
You can replace the put statement with an output statement or just use a sub-setting if statement.
Regards,
Amir.
Hi,
Since you mentioned 'library' instead of a folder/directory, I would assume you are trying to put data set names into a data set, and then there is a simple way: say you want every table names within 'work':
proc sql;
create table want as
select distinct memname as dname from dictionary.columns where libname='WORK';
QUIT;
Haikuo
Hikuo!
I am getting an empty result 😞
Please post your code. Make sure your libname need to be CAPITAL. for instance, libname='work' will NOT work, it has to be libname='WORK'.
Haikuo
Haikuo's code should have worked. What code did you submit and, if it was Haikuo's code literally, did you have any files in the WORK library?
If you changed the name of the libname, did you type the desired libname in all caps?
You also could have used dictionary.tables, but would get the same result. e.g.:
proc sql;
create table want as
select memname
from dictionary.tables
where libname='WORK'
;
QUIT;
I did not use CAPS.. that might be the reason. I figured out a different way now though... thx!
"I figured out a different way now though",
Care sharing with the forum?
Thanks,
Haikuo
Sure! I added another filter.. and this code might be slightly slower 😉
*-----------------------------------------------------------------------------+
| Daten aus dem Verzeichnis lls_wrk auslesen |
*-----------------------------------------------------------------------------;
proc contents directory data=lls_wrk._all_ out=temp short;
run;
*-----------------------------------------------------------------------------+
| relevante Tabellennamen filtern |
*-----------------------------------------------------------------------------;
proc sql;
create table lls_wrk as
select distinct memname
from temp
where substr(memname, 1, 2) = "P_";
quit;
you could add the filter to Art's code:
proc sql;
create table want as
select memname
from dictionary.tables
where libname='WORK' and substr(memname, 1, 2) = "P_";
quit;
Based on your example code (appears you are referencing library referenced by LLS_WRK), you would need one additional change to Linlin's modification of Art's code to make work:
proc sql;
create table want as
select memname
from dictionary.tables
where libname= "LLS_WRK" and substr(memname, 1, 2) = "P_";
quit;
Your example works just as well at the usage of dictionary.tables for your case. but using dictionary views can be more powerful for other things.
i'm recommending proc sql with sashelp.vmember rather than proc contents, dictionary.columns or dictionary.tables because it performs much better with non-standard libraries
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 25. Read more here about why you should contribute and what is in it for you!
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.