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