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

I'm want to read all the SAS datasets in a directory into a common datasets.  The individual datasets will expand over time.  Using the SAS libname, is there a way to do it without having to itemize each dataset name in the SET statement?

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

Do you want to try the code below? replace'your_libname' with your real libname and using capital letters in "

where libname='YOUR_LIBNAME'"

libname your_libname '???';

proc sql noprint;;

  select catx('.','your_libname',memname) into : dsn separated by ' '

    from dictionary.tables

        where libname='YOUR_LIBNAME'; /* libname must be capital letters */

quit;

%put &dsn;

data want;

   set &dsn;

run;

Linlin

View solution in original post

7 REPLIES 7
art297
Opal | Level 21

Do you have control over the filenames?  I ask because, if they can all start with the same character or string, then you can use a wildcard in your set statement.  e.g.:

libname mydata "c:\art\test";

data mydata.file1;

  set sashelp.class;

run;

data mydata.file2;

  set sashelp.class;

run;

data want;

  set mydata.f:;

run;

Mike7085
Calcite | Level 5

I don't currently, but the current number of datasets is relatively small, so that's an easy change fo fix the problem.  Thanks!!

ArtC
Rhodochrosite | Level 12

As your task becomes more complicated there are some macro language solutions as well.  Until then stick with the simple.

Linlin
Lapis Lazuli | Level 10

Do you want to try the code below? replace'your_libname' with your real libname and using capital letters in "

where libname='YOUR_LIBNAME'"

libname your_libname '???';

proc sql noprint;;

  select catx('.','your_libname',memname) into : dsn separated by ' '

    from dictionary.tables

        where libname='YOUR_LIBNAME'; /* libname must be capital letters */

quit;

%put &dsn;

data want;

   set &dsn;

run;

Linlin

Mike7085
Calcite | Level 5

Thanks, that worked beautifully and I didn't have to change any dataset names.  I have multiple types of datasets in the directory and was able to select the ones I wanted by adding :and memname like '%diff%' to the where clause.

proc  sql

data_null__
Jade | Level 19

As mentioned there is the relatevely new name range syntax for the SET statement data set names argument.  You will also want to look in the documentation for the INDSNAME=variable option.  And if the datasets have the same variables and lengths you can gain performance with OPEN=DEFER.

Howles
Quartz | Level 8

So the data are not static ("will expand over time") and will live in two places (the individual data sets and the common one). That's parallel maintenance, something to be avoided. Consider making the common data set a view.

Mike7085 wrote:

I'm want to read all the SAS datasets in a directory into a common datasets.  The individual datasets will expand over time.  Using the SAS libname, is there a way to do it without having to itemize each dataset name in the SET statement?

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 7 replies
  • 7402 views
  • 3 likes
  • 6 in conversation