Title: SAS Base Programming
1SAS Base Programming
- Temporary vs. Permanent SAS Data Sets
2SAS 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
3Temporary 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.61Miles PROC PRINT data distance RUN PRO
C PRINT data work.distance RUN
4Assigning 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 ltoptionsgt
Example
Iibname mylib\\mySAS\summer07\data
5Naming 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
mylib07
mylib07
mylib 07
6Two-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
7Lets 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.61Miles
- PROC PRINT data mylib.distance
- RUN
- direct reference
- PROC PRINT data 'C\Documents and
Settings\xxxx\distance' - RUN
8Browsing 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_
9Browsing a SAS data set
- To explore the description of a SAS data set,
specify the data set name in the DATAoption
PROC CONTENTS DATA libref.SAS-data-set-name
Example
PROC CONTENTS data mylib._all_ nods RUN PROC
CONTENTS data mylib.distance RUN