程序代写代做代考 MET MA 603: SAS Programming and Applications

MET MA 603: SAS Programming and Applications

MET MA 603:
SAS Programming and Applications

Libraries

1

1

Libraries
A Library is a location, specified by the user, that can store SAS datasets. Anywhere that a file can be saved may be defined as a library. Libraries are listed in the Explorer Window.
Libraries can be defined using point-and-click via Tools or by right-clicking inside the Explorer Window.
Libraries can also be defined using a Libname statement.
Example of Libname statement:
libname myLib “C:\Users\govonlu\Desktop\Data”;
Library naming rules are the same as for datasets and variables, except that length is restricted to 8 characters.
The default library used by SAS is named Work.

2

2

Using Libraries
Unless otherwise instructed, SAS uses the Work library. If another library is to be used, it must be referenced.
libname myLib “C:\Users\govonlu\Desktop\Data”;
data distance; Miles = 26.22; run;
data work.distance; Miles = 26.22; run;
data mylib.distance; Miles = 26.22; run;
A library name can be redefined.
libname myLib “C:\Users\govonlu\Desktop\Data”;
libname myLib “C:\Users\govonlu\Desktop\Data2”;
A statement can be used to clear one library name or to clear all library names.
libname myLib clear; libname _all_ clear;
All Library names are cleared once the SAS session ends.

3

3

Temporary vs. Permanent Datasets
SAS datasets are classified as Temporary or Permanent based on the library in which they are located.
A Temporary dataset is a dataset in the Work library. It will not be saved once the SAS session is ended.
A Permanent dataset is a dataset in any library other than the work library. It exists outside of the SAS session and will still exist once the SAS session is ended.
Examples of temporary datasets:
distance work.distance
Examples of permanent datasets:
mylib.distance mylib2.distance

4

4

The Work Library Explained
Each time SAS is launched, a folder is automatically created within (usually) the computer’s hard disk (i.e., C: drive). When temporary datasets are created, they are saved in this folder.
When the SAS session is closed, the folder, and it’s contents, is automatically deleted.
Note that if the SAS session is abnormally terminated (e.g., crashes), the folder may not get deleted. Performance may be impacted if too many large temporary files accumulate.

5

5

Practice
Create a folder named “MA603” on your desktop and use a Libname statement to define a library that refers to the folder. Name the library “practice”. Execute a Data step to create the Temperature dataset in your library. Is this dataset temporary or permanent?
Execute a statement that clears the library reference. What happens if you try to run your Data step again?

6

6

Practice
What error message do you receive if you execute a library statement, and the folder you reference does not exist?
What error message do you receive if you execute a library statement, and the Libname you are using does not conform to the naming rules?

7

7

Readings

Textbook sections 1.10, 2.18, 2.19

8

8

/docProps/thumbnail.jpeg