BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sfmeier
Obsidian | Level 7

How can I read the filenames from a library into a dataset?

Thx,

Stefan

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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

View solution in original post

11 REPLIES 11
Amir
PROC Star

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.

Haikuo
Onyx | Level 15

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

sfmeier
Obsidian | Level 7

Hikuo!

I am getting an empty result 😞

Haikuo
Onyx | Level 15

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

art297
Opal | Level 21

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;

sfmeier
Obsidian | Level 7

I did not use CAPS.. that might be the reason. I figured out a different way now though... thx!

Haikuo
Onyx | Level 15

"I figured out a different way now though",

Care sharing with the forum?

Thanks,

Haikuo

sfmeier
Obsidian | Level 7

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;


Linlin
Lapis Lazuli | Level 10

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;

LarryWorley
Fluorite | Level 6

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.

Peter_C
Rhodochrosite | Level 12

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 2678 views
  • 4 likes
  • 7 in conversation