DATA Step, Macro, Functions and more

Changing Library Names Across Multiple Programs

Accepted Solution Solved
Reply
Contributor
Posts: 62
Accepted Solution

Changing Library Names Across Multiple Programs

Let's say I have 10 SAS programs that each have the following at the top:

Libname MyLib "E:\MySASFiles";

Is there a way to only change the directory name in one of the programs and let the rest update auto-magically? I'm thinking %Include but i'm not familiar enough with this option. Any Hints?

Thank you!


Accepted Solutions
Solution
‎04-04-2014 03:10 PM
Super User
Posts: 19,849

Re: Changing Library Names Across Multiple Programs

Create a single .sas program that assigns libs.

Then put a %include at the top of your programs that includes the file above.

But that assumes you're not using the same name for diff libraries in different programs which I've also seen.

View solution in original post


All Replies
Solution
‎04-04-2014 03:10 PM
Super User
Posts: 19,849

Re: Changing Library Names Across Multiple Programs

Create a single .sas program that assigns libs.

Then put a %include at the top of your programs that includes the file above.

But that assumes you're not using the same name for diff libraries in different programs which I've also seen.

Regular Contributor
Posts: 217

Re: Changing Library Names Across Multiple Programs

Another option is to make 'E:\MySASFiles' a macro value and change all your libname statements to be

Libname MyLib "&mylib."; then, in the first program code %global mylib; %let mylib = E:\MySASFiles;


Super User
Posts: 11,343

Re: Changing Library Names Across Multiple Programs

For the libraries I use all of the time I have assignments in my autoexec.sas. I know that is "old school" BUT if I reconfigure my machine I only need to change the libname in one place.

I do not repeat the library assignments in each program.

Super User
Posts: 10,041

Re: Changing Library Names Across Multiple Programs

I would like to use CALL EXECUTE .

data fold;

input f : $40.;

cards;

c:\x

d:\d

;

run;

data _null_;

set fold;

call execute('%let f='||f ||' ; ');

call execute('%include a1 ;  ');

call execute('%include a2 ;  ');

call execute('%include a3 ;  ');

call execute('%include a4 ;  ');

run;

and change libname statement in all of program.

Libname MyLib " &f ";



Ksharp

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 268 views
  • 3 likes
  • 5 in conversation