Discussion:
SAS Library
(too old to reply)
Yue
2008-06-05 00:39:50 UTC
Permalink
Hi, buddies,

This is a piece from the Base Prep. quote"

You can also define additional libraries. In fact, often the first
step in setting up your SAS session is to define the libraries.

To define a library, you assign a library name (a libref) to it and
specify a path, such as a directory path. You will use the libref as
the first part of the file's two-level name (libref.filename) to
reference the file within the library. You can use programming
statements to assign library names.

Assigning Librefs
To define libraries, you can use a LIBNAME statement. You can store
the LIBNAME statement with any SAS program so that the SAS data
library is assigned each time the program is submitted.

General form, basic LIBNAME statement:

LIBNAME libref 'SAS-data-library';

where

libref is 1 to 8 characters long, begins with a letter or underscore,
and contains only letters, numbers, or underscores.

SAS-data-library is the name of a SAS data library in which SAS data
files are stored. The specification of the physical name of the
library differs by operating environment.

" " "

My understanding of the statement "LIBNAME libref 'SAS-data-library';"
is

libref is the name you assign to the library
and 'SAS-data-library' is the path of it.
but we need to have a library existing there first.

However, I tried to create a library "BasePrep", I see it under Active
Libraries, and I use the statement:

LIBNAME SASBase 'G:\SAS\BasePrep';

instead assign the name SASBase to library BasePrep, It gives a new
library SASBase under Active Libraries and saying "NOTE: Library
SASBASE does not exist" in the log.

??????

thanks!
Bucher Scott
2008-06-05 01:59:10 UTC
Permalink
Hi Yue,

It seems the folder G:\SAS\BasePrep does not exist. Libname statements do not create new folders, they sort of just point SAS to existing folders. Hence when you created the BasePrep library, it did not create G:\SAS\BasePrep. So assuming you have a folder named 'example' and you want to assign a library to it, you would use:

LIBNAME BasePrep 'G:\SAS\example';

If you then wanted to assign SASBase to the same folder use:

LIBNAME SASBase 'G:\SAS\example';


Neither of the libname statements created new folders.

Although I could be completely misunderstanding you, and perhaps you did indeed create a BasePrep folder?

Regards,
Scott Bucher




-----Original Message-----
From: SAS(r) Discussion on behalf of Yue
Sent: Wed 6/4/2008 8:39 PM
To: SAS-***@LISTSERV.UGA.EDU
Subject: SAS Library

Hi, buddies,

This is a piece from the Base Prep. quote"

You can also define additional libraries. In fact, often the first
step in setting up your SAS session is to define the libraries.

To define a library, you assign a library name (a libref) to it and
specify a path, such as a directory path. You will use the libref as
the first part of the file's two-level name (libref.filename) to
reference the file within the library. You can use programming
statements to assign library names.

Assigning Librefs
To define libraries, you can use a LIBNAME statement. You can store
the LIBNAME statement with any SAS program so that the SAS data
library is assigned each time the program is submitted.

General form, basic LIBNAME statement:

LIBNAME libref 'SAS-data-library';

where

libref is 1 to 8 characters long, begins with a letter or underscore,
and contains only letters, numbers, or underscores.

SAS-data-library is the name of a SAS data library in which SAS data
files are stored. The specification of the physical name of the
library differs by operating environment.

" " "

My understanding of the statement "LIBNAME libref 'SAS-data-library';"
is

libref is the name you assign to the library
and 'SAS-data-library' is the path of it.
but we need to have a library existing there first.

However, I tried to create a library "BasePrep", I see it under Active
Libraries, and I use the statement:

LIBNAME SASBase 'G:\SAS\BasePrep';

instead assign the name SASBase to library BasePrep, It gives a new
library SASBase under Active Libraries and saying "NOTE: Library
SASBASE does not exist" in the log.

??????

thanks!
Yue
2008-06-06 18:55:07 UTC
Permalink
Hi, Scott, thank you very much for the explaining!
I have several puzzles though, sorry that I am really a so new
bird. :p

- What's the relationship between a folder and a library? a folder = a
library?
- quote"when you created the BasePrep library, it did not create G:\SAS
\BasePrep" so what did it create then?
- quote"assuming you have a folder named 'example' and you want to
assign a library to it" Assign a library to a folder?
- quote"LIBNAME BasePrep 'G:\SAS\example'" So a library doesn't have a
path, but a folder does. can I assign 2 different libraries to the
same folder?

thanks so much.
Yue
Post by Bucher Scott
Hi Yue,
LIBNAME BasePrep 'G:\SAS\example';
LIBNAME SASBase 'G:\SAS\example';
Neither of the libname statements created new folders.
Although I could be completely misunderstanding you, and perhaps you did indeed create a BasePrep folder?
Regards,
Scott Bucher
Jack Hamilton
2008-06-06 19:57:57 UTC
Permalink
Post by Yue
Hi, Scott, thank you very much for the explaining!
I have several puzzles though, sorry that I am really a so new
bird. :p
- What's the relationship between a folder and a library? a folder = a
library?
A folder is a way for the operating system to organize or group files.

A SAS library is a way for SAS to to refer to a group of SAS data sets
(and other objects).

Typically, there is a one-to-one relationship between an OS folder (or
directory) and a SAS library, but one-to many and many-to-one are also
possible.
Post by Yue
\SAS
\BasePrep" so what did it create then?
It creates an association, within SAS, between a directory name and a
SAS libname. It does not create the directory.
Post by Yue
- quote"assuming you have a folder named 'example' and you want to
assign a library to it" Assign a library to a folder?
Yes. That's one way to put it.
Post by Yue
- quote"LIBNAME BasePrep 'G:\SAS\example'" So a library doesn't have a
path, but a folder does. can I assign 2 different libraries to the
same folder?
Yes. Here is code and a log from SAS for Windows. "c:\temp" and "c:
\temp2" exist, and "c:\temp3" does not exist.

=====
libname temp1 'c:\temp';
libname temp2 'c:\temp2';
libname temp3 'c:\temp3';
libname temp4 'c:\temp';
libname temps (temp1 temp2);
=====

and the log:

=====
1 libname temp1 'c:\temp';
NOTE: Libref TEMP1 was successfully assigned as follows:
Engine: V9
Physical Name: c:\temp
2 libname temp2 'c:\temp2';
NOTE: Libref TEMP2 was successfully assigned as follows:
Engine: V9
Physical Name: c:\temp2
3 libname temp3 'c:\temp3';
NOTE: Library TEMP3 does not exist.
4 libname temp4 'c:\temp';
NOTE: Libname TEMP4 refers to the same physical library as TEMP1.
NOTE: Libref TEMP4 was successfully assigned as follows:
Engine: V9
Physical Name: c:\temp
5 libname temps (temp1 temp2);
NOTE: Libref TEMPS was successfully assigned as follows:
Levels: 2
Engine(1): V9
Physical Name(1): c:\temp
Engine(2): V9
Physical Name(2): c:\temp2
=====

libnames temp1 and temp2 refer to real directories and can be used as
you might expect. libname temp3 refers to a non-existent directory,
and you will get an error message when you try to use it. libnames
temp1 and temp4 refer to the same physical directory, and can (in most
cases) be used interchangeably. libname temps refers to both c:\temp
and c:\temp2; SAS will look first in c:\temp, and then in c:\temp2
when searching for a data set, and will write any new data sets into c:
\temp2.

That's the simplified version.
Post by Yue
thanks so much.
Yue
Post by Bucher Scott
Hi Yue,
It seems the folder G:\SAS\BasePrep does not exist. Libname
statements do not create new folders, they sort of just point SAS
to existing folders. Hence when you created the BasePrep library,
it did not create G:\SAS\BasePrep. So assuming you have a folder
named 'example' and you want to assign a library to it, you would
LIBNAME BasePrep 'G:\SAS\example';
LIBNAME SASBase 'G:\SAS\example';
Neither of the libname statements created new folders.
Although I could be completely misunderstanding you, and perhaps
you did indeed create a BasePrep folder?
Regards,
Scott Bucher
Chang Chung
2008-06-06 20:35:46 UTC
Permalink
On Fri, 6 Jun 2008 12:57:57 -0700, Jack Hamilton <***@STANFORDALUMNI.ORG> wrote:
...
Post by Jack Hamilton
libname temp1 'c:\temp';
libname temp2 'c:\temp2';
libname temp3 'c:\temp3';
libname temp4 'c:\temp';
libname temps (temp1 temp2);
...

hi,
in addition to Jack's excellent explanation, here are some fun facts about
libname statement on windows platform (9.1.3). happy friday!
cheers,
chang

libname one "d:\your dir\";
libname two "d:\your dir\..\your dir\";
/* on log
NOTE: Libname TWO refers to the same physical library as ONE.
*/
proc sql;
describe table dictionary.libnames;
select libname, path, level
from dictionary.libnames;
quit;

Loading...