hechsp 001 chapter 3
DESCRIPTION
TRANSCRIPT
Chapter 3
Getting Familiar with SAS® Data Sets
Section 3.1
SAS Data Libraries
3 3
Objectives Explain the concept of a SAS data library. State the difference between a permanent library and
a temporary library. Use the CONTENTS procedure to investigate a SAS
data library.
4 4
SAS Vocabulary SAS data library LIBREF Temporary library Permanent library LIBNAME libref.filename PROC CONTENTS _ALL_ NODS
5 5
You need to reference SAS data sets in your programs.
Typing the full path every time that you use or create a data set is inefficient and time-consuming. SAS enables you to give a nickname to the fully qualified pathname.
You can have a nickname for every different folder that contains SAS data.
SAS Data Libraries
6 6
SAS Data LibrariesFor Windows, a SAS data library is simply a directory.
Each different location that contains SAS files is called a SAS data library.
Example:
c:\workshop\mysasfiles
This is the fully qualified pathname of the SAS data library.
7 7
FILES
LIBRARIES
You can think of a SAS data library as a drawer in a filing cabinet and a SAS data set as one of the file folders in the drawer.
SAS Data Libraries
8 8
You identify SAS data libraries by assigning each a library reference name (libref).
This is simply a nickname that you can use later to refer to the location.
libref
Assigning a Libref
9 9
Work
Sasuser
work - temporary library
sasuser - permanent library
When you start SAS, you automatically have access to a temporary SAS data library and a permanent SAS data library.
SAS Data Libraries
1010
SAS Data LibrariesWork library (temporary)
When you end or close your SAS session, all files in this library are deleted.
Sasuser library (permanent)
Files in this library are permanent, and are therefore saved after your SAS session ends.
1111
Work
Sasuser
ia
work - temporary library
sasuser - permanent library
When you start SAS, you automatically have access to a temporary SAS data library and a permanent SAS data library.
You can create and access your own permanent libraries such as the one you named ia.
ia - permanent library
SAS Data Libraries
1212
LIBNAME libref 'physical address of file';LIBNAME libref 'physical address of file';
Assigning a LibrefUse the LIBNAME statement to assign a libref (nickname) to a SAS data library.
General form of the LIBNAME statement:
libname ia 'c:\workshop\winsas\prog1';
1313
Assigning a Libref
LIBNAME is the keyword. The libref is the nickname that you choose. Rules for naming a libref:
– must be 8 characters or less– must begin with a letter or an underscore
Remaining characters can be letters, numbers, or underscores.
LIBNAME libref 'physical address of file';LIBNAME libref 'physical address of file';
1414
Assigning a LibrefThis is similar to putting a sticker on the front of the file cabinet drawer.
Work
Sasuser
ia
When you use the nickname, SAS knows where to look for the SAS data sets.
1515
When you submit the LIBNAME statement, a connection is made between the libref (nickname) and the physical location of files on your operating system.
'c:\workshop\winsas\prog1'
Making the Connection
1616
Assigning a LibrefThe LIBNAME statement is a global statement: It is a stand-alone statement.
It does not need to go inside a step. It does not need a RUN statement. The library remains in effect until you
change it delete it exit SAS.
You only have to submit the statement once in your SAS session.
1717
Submit a LIBNAME statement to tell SAS about the library.
You have data in two different directories: The data for college tracking is located at C:\
CollegeData. The data for the school trips is located at C:\
ExtraCurricular\SeniorTrip.
You need to submit a LIBNAME statement for every different folder (not data set).
Making the Connection
1818
In the Editor window, submit the following statements:
Making the Connection
libname college 'C:\CollegeData';
libname trip 'C:\ExtraCurricular\Senior Trip';
1919
The first name (libref)refers to the library.
Every SAS file has a two-level name:
libref.filename
The data set ia.sales is a SAS file in the ia library.
The second name(filename) refersto the file in the library.
Two-level SAS Filenames
Sasuser
Work
ia
sales
2020
work.employee employee
Temporary SAS FilenameThe libref work can be omitted when you refer to a file in the Work library.
The default libref is work if the libref is omitted.
2121
Temporary SAS FilenameThink back to the paper exercise that you did in Chapter 2, naming a data set.
What did you name your data set?
What library would SAS think that was in?
2222
To explore the descriptor portion of a SAS data set, specify the data set name in the DATA= option.
PROC CONTENTS DATA=libref.SAS-data-set-name;RUN;
PROC CONTENTS DATA=libref.SAS-data-set-name;RUN;
Browsing a SAS Data Library
This enables you to see the descriptor portion of the crew data set in the International Airlines library.
proc contents data=ia.crew;run;
2323
PROC CONTENTS Output – Part 1
The SAS System
The CONTENTS Procedure
Data Set Name IA.CREW Observations 69Member Type DATA Variables 8Engine V9 Indexes 0Created Friday, June 29, Observation Length 120 2001 03:15:27 PMLast Modified Friday, June 29, Deleted Observations 0 2001 03:41:07 PMProtection Compressed NOData Set Type Sorted NOLabelData Representation WINDOWS_32Encoding Default
Partial PROC CONTENTS Output
continued...
2424
PROC CONTENTS Output – Part 2
Engine/Host Dependent Information
Data Set Page Size 12288Number of Data Set Pages 1First Data Page 1Max Obs per Page 102Obs in First Data Page 69Number of Data Set Repairs 0File Name C:\workshop\winsas\ prog1\crew.sas7bdatRelease Created 8.0202M0Host Created WIN_PRO
Partial PROC CONTENTS Output
continued...
2525
Alphabetic List of Variables and Attributes
# Variable Type Len Format Informat
6 EmpID Char 6 3 FirstName Char 32 1 HireDate Num 8 DATE9. DATE9. 7 JobCode Char 6 2 LastName Char 32 4 Location Char 16 5 Phone Char 8 8 Salary Num 8
PROC CONTENTS Output – Part 3Partial PROC CONTENTS Output
2626
You might want a list of all the SAS files in a library, or the descriptor portion of all the SAS data sets in a particular library.
Use the _ALL_ keyword to list all the SAS files in the library and the descriptor portion of every data set in that library.
PROC CONTENTS DATA=libref._ALL_;RUN;
PROC CONTENTS DATA=libref._ALL_;RUN;
proc contents data=ia._all_;run;
Browsing a SAS Data Library
2727
You might not want the descriptor portion listed for each data set in the SAS library. That might be too much output.
What if you only want a list of all the SAS files in the library?
Browsing a SAS Data Library
2828
Use the NODS option with the _ALL_ keyword to suppress the descriptor information for all the data sets.
General form of the NODS option:
PROC CONTENTS DATA=libref._ALL_ NODS;RUN;
PROC CONTENTS DATA=libref._ALL_ NODS;RUN;
Browsing a SAS Data Library
The NODS option can only be usedwith the keyword _ALL_.
Remember
2929
PROC CONTENTS DATA=libref._ALL_ NODS;RUN;
PROC CONTENTS DATA=libref._ALL_ NODS;RUN;
Browsing a SAS Data LibraryGeneral form of the NODS option:
proc contents data=ia._all_ nods;run;
There is a space between the _ALL_ and NODS options.
Remember
3030
Partial PROC CONTENTS Output
PROC CONTENTS Output
The SAS System
The CONTENTS Procedure
Directory
Libref IA Engine V9 Physical Name C:\workshop\winsas\prog1 File Name C:\workshop\winsas\prog1
Member File # Name Type Size Last Modified
1 ALLGOALS DATA 5120 31Jul01:08:52:34 2 ALLGOALS2 DATA 5120 31Jul01:08:52:38 3 ALLSALES DATA 5120 31Jul01:08:53:28 4 ALLSALES2 DATA 5120 31Jul01:08:53:46 5 APRTARGET DATA 17408 13Aug01:08:41:42 6 CHICAGO DATA 17408 31Jul01:08:54:38
3131
This exercise reinforces the concepts discussed previously.
Exercise – Section 3.1
Section 3.2
Exploring Your SAS Environment
3333
This exercise reinforces the concepts discussed previously.
Exercise – Section 3.2