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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 677 views
  • 0 likes
  • 3 in conversation