DATA Step, Macro, Functions and more

Libname and filename to multiple location

Reply
Regular Contributor
Posts: 239

Libname and filename to multiple location

Libname Test1 (C:\t1, C:\t2, C:\t3);

 

 

Filename Test2 (C:\t1, C:\t2, C:\t3);

 

 

Ques 1- In Libname, If all three folder do not exist then Libname gives WARNING but for filename there is no such warning generated. Why?

 

Ques 2- For libname/Filename, if member exists in multiple folder then which member would be refferred ? Example - Data1.sas7bdat with different columns exists in t1 and t2 folder then which Data1 would come in libname. I think it will take from t1 folder as it is written first. Please confirm whether order of folder name matters? Is the same concept applies on Filename.

 

 

Super User
Posts: 17,737

Re: Libname and filename to multiple location

Q1. You can use a filename to create a file, in this case it doesn't need to preexist to create a file.

 

I don't know the answer to Q2

 

 

Super User
Posts: 6,927

Re: Libname and filename to multiple location

Since a filename can be used to create a new file, SAS doesn't complain if no file is present at the time you define the file reference.

A library must be present at the time the libname is executed.

If you want to create new files/datasets, spanned definitions are a BAD IDEA. Don't do it.

And if you're not sure what is where, don't use them either. Be specific.

 

- Computers are dumb ("Computer sind doof" - Spliff, 1984)

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super Contributor
Posts: 394

Re: Libname and filename to multiple location

Q2 is easy enough to test. What is the output from this program?

 

libname t1 "C:\t1";
libname t2 "C:\t2";
data t1.test;
	x = 'This is the data set in T1';
data t2.test;
	x = 'This is the data set in T2';
libname both ("C:\t1" "C:\t2");
title 'T1 is first';
proc print data=both.test;
run;
libname both clear;
libname both ("C:\t2" "C:\t1");
title 'T2 is first';
proc print data=both.test;
run;
Ask a Question
Discussion stats
  • 3 replies
  • 229 views
  • 0 likes
  • 4 in conversation