SAS Base Programming

advertisement
SAS Base Programming
Temporary vs. Permanent SAS Data Sets
SAS Data Library
 When you invoke SAS, you automatically have
access to temporary and a permanent SAS data
library.
work – temporary library
sasuser – permanent library
libref – permanent library
You can create and access your
own permanent libraries
Temporary SAS data set
 By default, SAS data set you create is stored in the
work library.
 The SAS data set in the work library exists only
during the current job or session, and automatically
erased when you exit SAS.
DATA distance;
Miles = 26.22;
Kilomeers = 1.61*Miles;
PROC PRINT data = distance;
RUN;
PROC PRINT data = work.distance;
RUN;
Assigning a libref
 You can use the LIBNAME statement to assign a
libref to a SAS data library.
General form of the LIBNAME statement
LIBNAME libref ‘SAS-data-library’ <options>
Example
Iibname mylib”\\mySAS\summer07\data”;
Naming a libref
 Rules for naming a libref
must be 8 characters or less
must begin with a letter or underscore
remaining characters are letters, numbers, or
underscores.
Example
____OK____
____not OK____
mylib_07
07_mylib
_07mylib
mylib#07
mylib07
mylib 07
Two-level SAS filenames
 Every SAS file has a two-level name
libref.filename
Second name (filename) refers
to the file in the library
First name (libref) refers to the library
Let’s try!
* Create a Library named mylib;
libname mylib 'C:\Documents and Settings\xxxx';
* Permanent SAS Data Set;
DATA mylib.distance;
Miles = 26.22;
Kilometers = 1.61*Miles;
PROC PRINT data = mylib.distance;
RUN;
* direct reference;
PROC PRINT data = 'C:\Documents and Settings\xxxx\distance';
RUN;
Browsing a SAS data library
 Use the _ALL_ keyword to list all the SAS files in
the library and the NODS option to suppress the
descriptor portions of the data sets.
General form of the NODS option
PROC CONTENTS DATA =libref._ALL_ NODS;
NODS must be used in conjunction with the keyword _ALL_
Browsing a SAS data set
 To explore the description of a SAS data set,
specify the data set name in the DATA=option
PROC CONTENTS DATA =libref.SAS-data-set-name;
Example
PROC CONTENTS data = mylib._all_ nods;
RUN;
PROC CONTENTS data = mylib.distance;
RUN;
Download