hechsp 001 chapter 3
DESCRIPTION
TRANSCRIPT
![Page 1: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/1.jpg)
Chapter 3
Getting Familiar with SAS® Data Sets
![Page 2: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/2.jpg)
Section 3.1
SAS Data Libraries
![Page 3: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/3.jpg)
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.
![Page 4: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/4.jpg)
4 4
SAS Vocabulary SAS data library LIBREF Temporary library Permanent library LIBNAME libref.filename PROC CONTENTS _ALL_ NODS
![Page 5: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/5.jpg)
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
![Page 6: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/6.jpg)
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.
![Page 7: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/7.jpg)
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
![Page 8: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/8.jpg)
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
![Page 9: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/9.jpg)
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
![Page 10: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/10.jpg)
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.
![Page 11: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/11.jpg)
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
![Page 12: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/12.jpg)
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';
![Page 13: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/13.jpg)
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';
![Page 14: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/14.jpg)
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.
![Page 15: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/15.jpg)
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
![Page 16: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/16.jpg)
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.
![Page 17: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/17.jpg)
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
![Page 18: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/18.jpg)
1818
In the Editor window, submit the following statements:
Making the Connection
libname college 'C:\CollegeData';
libname trip 'C:\ExtraCurricular\Senior Trip';
![Page 19: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/19.jpg)
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
![Page 20: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/20.jpg)
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.
![Page 21: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/21.jpg)
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?
![Page 22: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/22.jpg)
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;
![Page 23: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/23.jpg)
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...
![Page 24: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/24.jpg)
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...
![Page 25: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/25.jpg)
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
![Page 26: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/26.jpg)
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
![Page 27: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/27.jpg)
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
![Page 28: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/28.jpg)
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
![Page 29: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/29.jpg)
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
![Page 30: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/30.jpg)
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
![Page 31: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/31.jpg)
3131
This exercise reinforces the concepts discussed previously.
Exercise – Section 3.1
![Page 32: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/32.jpg)
Section 3.2
Exploring Your SAS Environment
![Page 33: Hechsp 001 Chapter 3](https://reader033.vdocuments.mx/reader033/viewer/2022061211/5492e560b47959834a8b45cd/html5/thumbnails/33.jpg)
3333
This exercise reinforces the concepts discussed previously.
Exercise – Section 3.2