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

I was wondering if I could libname a directory containing serveral folders with datasets I need.

The directory looks like this:

Directory_A
--Directory_B
----Dataset_1.sas7bdat
--Directory_C
----Dataset_2.sas7bdat
----Dataset_3.sas7bdat
--Directory_D
----Dataset_4.sas7bdat

Cheers.
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If you do not have many folders involved easiest might be a macro variable to hold the main part of the path common to all such as:

 

%let path=C:\Directory_A\;
libname mylib ("&path.directory_B &path.directory_C &path.directory_D");

of course using appropriate syntax for your operating system and care for letter case if needed.

 

The last \ is just part of Windows paths. Alternatively if you like you could use

%let path=C:\Directory_A;
libname mylib ("&path.\directory_B &path.\directory_C &path.\directory_D");

The periods are necessary to indicate the end of the macro variable value. Do not insert spaces if not in the in actual path if not there.

 

 

&path.\directory_B resolves to "C:\Directory_A\directory_B"  &path.\ directory_B would resolve to "C:\Directory_A\ directory_B".  One of which is incorrect for your use.

View solution in original post

2 REPLIES 2
Reeza
Super User

You can have multiple paths in a library but I don't know of a way to have a wildcard reference. You could crawl the parent directory and concatenate the paths into one and pass it to a libname function or statement. I don't have time to code that up, but perhaps someone else can. There are examples of finding paths/folder structures on here or search SAS 9.4 Macro Appendix for an example.

 


@alex_liang wrote:
Hi,

I was wondering if I could libname a directory containing serveral folders with datasets I need.

The directory looks like this:

Directory_A
--Directory_B
----Dataset_1.sas7bdat
--Directory_C
----Dataset_2.sas7bdat
----Dataset_3.sas7bdat
--Directory_D
----Dataset_4.sas7bdat

Cheers.

 

 

ballardw
Super User

If you do not have many folders involved easiest might be a macro variable to hold the main part of the path common to all such as:

 

%let path=C:\Directory_A\;
libname mylib ("&path.directory_B &path.directory_C &path.directory_D");

of course using appropriate syntax for your operating system and care for letter case if needed.

 

The last \ is just part of Windows paths. Alternatively if you like you could use

%let path=C:\Directory_A;
libname mylib ("&path.\directory_B &path.\directory_C &path.\directory_D");

The periods are necessary to indicate the end of the macro variable value. Do not insert spaces if not in the in actual path if not there.

 

 

&path.\directory_B resolves to "C:\Directory_A\directory_B"  &path.\ directory_B would resolve to "C:\Directory_A\ directory_B".  One of which is incorrect for your use.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 2 replies
  • 1056 views
  • 0 likes
  • 3 in conversation