Hechsp 001 Chapter 3


Published on

Published in: Education
1 Comment
  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Hechsp 001 Chapter 3

    1. 1. Chapter 3 Getting Familiar with SAS ® Data Sets
    2. 2. Section 3.1 SAS Data Libraries
    3. 3. Objectives <ul><ul><li>Explain the concept of a SAS data library. </li></ul></ul><ul><ul><li>State the difference between a permanent library and a temporary library. </li></ul></ul><ul><ul><li>Use the CONTENTS procedure to investigate a SAS data library. </li></ul></ul>
    4. 4. SAS Vocabulary <ul><ul><li>SAS data library </li></ul></ul><ul><ul><li>LIBREF </li></ul></ul><ul><ul><li>Temporary library </li></ul></ul><ul><ul><li>Permanent library </li></ul></ul><ul><ul><li>LIBNAME </li></ul></ul><ul><ul><li>libref . filename </li></ul></ul><ul><ul><li>PROC CONTENTS </li></ul></ul><ul><ul><li>_ALL_ </li></ul></ul><ul><ul><li>NODS </li></ul></ul>
    5. 5. SAS Data Libraries 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.
    6. 6. SAS Data Libraries For Windows, a SAS data library is simply a directory. Each different location that contains SAS files is called a SAS data library. Example: c:workshopmysasfiles This is the fully qualified pathname of the SAS data library.
    7. 7. SAS Data 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. FILES LIBRARIES
    8. 8. <ul><li>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. </li></ul>Assigning a Libref libref
    9. 9. <ul><li>work - temporary library </li></ul><ul><li>sasuser - permanent library </li></ul>SAS Data Libraries When you start SAS, you automatically have access to a temporary SAS data library and a permanent SAS data library. Work Sasuser
    10. 10. SAS Data Libraries <ul><li>Work library (temporary) </li></ul><ul><ul><ul><li>When you end or close your SAS session, all files in this library are deleted. </li></ul></ul></ul><ul><li>Sasuser library (permanent) </li></ul><ul><ul><ul><li>Files in this library are permanent, and are therefore saved after your SAS session ends. </li></ul></ul></ul>
    11. 11. <ul><li>work - temporary library </li></ul><ul><li>sasuser - permanent library </li></ul>SAS Data Libraries 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 Work Sasuser ia
    12. 12. Assigning a Libref <ul><li>Use the LIBNAME statement to assign a libref (nickname) to a SAS data library. </li></ul><ul><li>General form of the LIBNAME statement: </li></ul>LIBNAME libref ' physical address of file ' ; libname ia 'c:workshopwinsasprog1';
    13. 13. Assigning a Libref <ul><ul><li>LIBNAME is the keyword. </li></ul></ul><ul><ul><li>The libref is the nickname that you choose. </li></ul></ul><ul><ul><li>Rules for naming a libref: </li></ul></ul><ul><ul><ul><li>must be 8 characters or less </li></ul></ul></ul><ul><ul><ul><li>must begin with a letter or an underscore </li></ul></ul></ul><ul><ul><li>Remaining characters can be letters, numbers, or underscores. </li></ul></ul>LIBNAME libref ' physical address of file ' ;
    14. 14. Assigning a Libref <ul><li>This is similar to putting a sticker on the front of the file cabinet drawer. </li></ul>When you use the nickname, SAS knows where to look for the SAS data sets. Work Sasuser ia
    15. 15. <ul><li>When you submit the LIBNAME statement, a connection is made between the libref (nickname) and the physical location of files on your operating system. </li></ul>Making the Connection 'c:workshopwinsasprog1'
    16. 16. Assigning a Libref <ul><li>The LIBNAME statement is a global statement: </li></ul><ul><ul><li>It is a stand-alone statement. It does not need to go inside a step. </li></ul></ul><ul><ul><li>It does not need a RUN statement. </li></ul></ul><ul><ul><li>The library remains in effect until you </li></ul></ul><ul><ul><ul><li>change it </li></ul></ul></ul><ul><ul><ul><li>delete it </li></ul></ul></ul><ul><ul><ul><li>exit SAS. </li></ul></ul></ul><ul><li>You only have to submit the statement once in your SAS session. </li></ul>
    17. 17. <ul><li>Submit a LIBNAME statement to tell SAS about the library. </li></ul><ul><li>You have data in two different directories: </li></ul><ul><ul><li>The data for college tracking is located at C:CollegeData. </li></ul></ul><ul><ul><li>The data for the school trips is located at C:ExtraCurricularSeniorTrip. </li></ul></ul><ul><li>You need to submit a LIBNAME statement for every different folder (not data set). </li></ul>Making the Connection
    18. 18. <ul><li>In the Editor window, submit the following statements: </li></ul>Making the Connection libname college 'C:CollegeData'; libname trip 'C:ExtraCurricularSenior Trip';
    19. 19. <ul><ul><li>The first name ( libref ) refers to the library. </li></ul></ul>Two-level SAS Filenames Every SAS file has a two-level name: libref . filename The data set ia . sales is a SAS file in the ia library. <ul><ul><li>The second name ( filename ) refers to the file in the library. </li></ul></ul>Sasuser Work ia sales
    20. 20. Temporary SAS Filename <ul><li>The libref work can be omitted when you refer to a file in the Work library. </li></ul><ul><li>The default libref is work if the libref is omitted. </li></ul>work.employee employee
    21. 21. Temporary SAS Filename <ul><li>Think back to the paper exercise that you did in Chapter 2, naming a data set. </li></ul><ul><li>What did you name your data set? </li></ul><ul><li>What library would SAS think that was in? </li></ul>
    22. 22. <ul><li>To explore the descriptor portion of a SAS data set, specify the data set name in the DATA= option. </li></ul>Browsing a SAS Data Library PROC CONTENTS DATA= libref.SAS-data-set-name ; RUN; This enables you to see the descriptor portion of the crew data set in the International Airlines library. proc contents data=ia.crew; run;
    23. 23. PROC CONTENTS Output – Part 1 The SAS System The CONTENTS Procedure Data Set Name IA.CREW Observations 69 Member Type DATA Variables 8 Engine V9 Indexes 0 Created Friday, June 29, Observation Length 120 2001 03:15:27 PM Last Modified Friday, June 29, Deleted Observations 0 2001 03:41:07 PM Protection Compressed NO Data Set Type Sorted NO Label Data Representation WINDOWS_32 Encoding Default Partial PROC CONTENTS Output continued...
    24. 24. PROC CONTENTS Output – Part 2 Engine/Host Dependent Information Data Set Page Size 12288 Number of Data Set Pages 1 First Data Page 1 Max Obs per Page 102 Obs in First Data Page 69 Number of Data Set Repairs 0 File Name C:workshopwinsas prog1crew.sas7bdat Release Created 8.0202M0 Host Created WIN_PRO Partial PROC CONTENTS Output continued...
    25. 25. PROC CONTENTS Output – Part 3 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 Partial PROC CONTENTS Output
    26. 26. <ul><li>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. </li></ul><ul><li>Use the _ALL_ keyword to list all the SAS files in the library and the descriptor portion of every data set in that library. </li></ul>Browsing a SAS Data Library PROC CONTENTS DATA= libref ._ALL_ ; RUN; proc contents data=ia._all_; run;
    27. 27. <ul><li>You might not want the descriptor portion listed for each data set in the SAS library. That might be too much output. </li></ul><ul><li>What if you only want a list of all the SAS files in the library? </li></ul>Browsing a SAS Data Library
    28. 28. <ul><li>Use the NODS option with the _ALL_ keyword to suppress the descriptor information for all the data sets. </li></ul><ul><li>General form of the NODS option: </li></ul>Browsing a SAS Data Library PROC CONTENTS DATA= libref ._ALL_ NODS ; RUN; The NODS option can only be used with the keyword _ALL_ . Remember
    29. 29. Browsing a SAS Data Library <ul><li>General form of the NODS option: </li></ul>PROC CONTENTS DATA= libref ._ALL_ NODS ; RUN; proc contents data=ia._all_ nods; run; There is a space between the _ALL_ and NODS options. Remember
    30. 30. PROC CONTENTS Output Partial PROC CONTENTS Output The SAS System The CONTENTS Procedure Directory Libref IA Engine V9 Physical Name C:workshopwinsasprog1 File Name C:workshopwinsasprog1 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
    31. 31. <ul><li>This exercise reinforces the concepts discussed previously. </li></ul>Exercise – Section 3.1
    32. 32. Section 3.2 Exploring Your SAS Environment
    33. 33. <ul><li>This exercise reinforces the concepts discussed previously. </li></ul>Exercise – Section 3.2