1 / 33

Chapter 3

Chapter 3. Getting Familiar with SAS ® Data Sets. Section 3.1. SAS Data Libraries. 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. SAS Vocabulary.

narcisse
Download Presentation

Chapter 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 3 Getting Familiar with SAS® Data Sets

  2. Section 3.1 SAS Data Libraries

  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. SAS Vocabulary • SAS data library • LIBREF • Temporary library • Permanent library • LIBNAME • libref.filename • PROC CONTENTS • _ALL_ • NODS

  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. 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:\workshop\mysasfiles This is the fully qualified pathname of the SAS data library.

  7. FILES LIBRARIES 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.

  8. Assigning a Libref • 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

  9. Work Sasuser SAS Data Libraries When you start SAS, you automatically have access to a temporary SAS data library and a permanent SAS data library. • work - temporary library • sasuser- permanent library

  10. SAS Data Libraries • Work library (temporary) When you end or close your SAS session, all files in this library are deleted. • Sasuserlibrary (permanent) Files in this library are permanent, and are therefore saved after your SAS session ends.

  11. Work Sasuser ia SAS Data Libraries When you start SAS, you automatically have access to a temporary SAS data library and a permanent SAS data library. • work - temporary library • sasuser - permanent library ia - permanent library You can create and access your own permanent libraries such as the one you named ia.

  12. Assigning a Libref • Use the LIBNAME statement to assign a libref (nickname) to a SAS data library. • General form of the LIBNAME statement: LIBNAME libref 'physical address of file'; libname ia 'c:\workshop\winsas\prog1';

  13. 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';

  14. Work Sasuser ia Assigning a Libref • This is similar to putting a sticker on the front of the file cabinet drawer. When you use the nickname, SAS knows where to look for the SAS data sets.

  15. Making the Connection • 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'

  16. Assigning a Libref • The 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.

  17. Making the Connection • 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).

  18. Making the Connection • In the Editor window, submit the following statements: libname college 'C:\CollegeData'; libname trip 'C:\ExtraCurricular\Senior Trip';

  19. Work sales Sasuser ia Two-level SAS Filenames Every SAS file has a two-level name: libref.filename The data set ia.salesis a SAS file in the ia library. • The first name (libref)refers to the library. • The second name(filename) refersto the file in the library.

  20. work.employee employee Temporary SAS Filename • The 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.

  21. Temporary SAS Filename • Think 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?

  22. Browsing a SAS Data Library • 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=ia.crew;run; This enables you to see the descriptor portion of the crew data set in the International Airlines library.

  23. PROC CONTENTS Output – Part 1 Partial PROC CONTENTS Output 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 continued...

  24. PROC CONTENTS Output – Part 2 Partial PROC CONTENTS Output 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:\workshop\winsas\ prog1\crew.sas7bdat Release Created 8.0202M0 Host Created WIN_PRO continued...

  25. PROC CONTENTS Output – Part 3 Partial PROC CONTENTS Output 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

  26. Browsing a SAS Data Library • 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=ia._all_;run;

  27. Browsing a SAS Data Library • 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?

  28. Remember Browsing a SAS Data Library • 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; The NODS option can only be usedwith the keyword _ALL_.

  29. Remember Browsing a SAS Data Library • General form of the NODS option: PROC CONTENTS DATA=libref._ALL_ NODS;RUN; There is a space between the _ALL_ and NODS options. proc contents data=ia._all_ nods;run;

  30. PROC CONTENTS Output Partial 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

  31. Exercise – Section 3.1 • This exercise reinforces the concepts discussed previously.

  32. Section 3.2 Exploring Your SAS Environment

  33. Exercise – Section 3.2 • This exercise reinforces the concepts discussed previously.

More Related