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.
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.
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.
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.