Notes3 - SAS Data Sets SAS data sets have a descriptor portion and a data portion Notes 3 SAS Data Sets and Libraries Descriptor Portion General

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: SAS Data Sets SAS data sets have a descriptor portion and a data portion. Notes 3: SAS Data Sets and Libraries Descriptor Portion General data set information * data set name * data set label * date/time created * storage information * number of observations Information for each variable * Name * Type * Length * Position * Format * Informat * Label Data Portion 1 4 SAS Data Set Terminology SAS documentation and text in the SAS windowing environment use the following terms interchangeably: SAS Data Set SAS Data Set Variable Variable Observation Observation SAS Table SAS Table Column Column Row Row Browsing the Descriptor Portion The descriptor portion of a SAS data set contains general information about the SAS data set (such as data set name and number of observations) variable attributes (name, type, length, position, informat, format, label). The CONTENTS procedure displays the descriptor portion of a SAS data set. 2 5 SAS Data Sets Data Entry External File Other Software Files Browsing the Descriptor Portion 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; PROC CONTENTS DATA=libref.SAS-data-set-name; RUN; RUN; proc contents data=st.crew; run; Data Portion Conversion Process SAS Data Set Descriptor Portion 3 6 1 PROC CONTENTS Output Part 1 The SAS System The CONTENTS Procedure Data Set Name Member Type Engine Created Last Modified Protection Data Set Type Label Data Representation Encoding ST.CREW DATA V9 Friday, June 29, 2001 03:15:27 PM Friday, June 29, 2001 03:41:07 PM Observations Variables Indexes Observation Length Deleted Observations Compressed Sorted WINDOWS_32 Default 69 8 0 120 0 NO NO SAS Data Sets: Data Portion The data portion of a SAS data set is a rectangular table of character and/or numeric data values. LastName TORRES LANGKAMM SMITH WAGSCHAL TOERMOEN FirstName JAN SARAH MICHAEL NADJA JOCHEN JobTitle Pilot Mechanic Mechanic Pilot Pilot Salary 50000 80000 40000 77500 65000 Variable names Variable values Character values 7 Numeric values 10 PROC CONTENTS Output Part 2 Engine/Host Dependent Information Data Set Page Size Number of Data Set Pages First Data Page Max Obs per Page Obs in First Data Page Number of Data Set Repairs File Name Release Created Host Created 12288 1 1 102 69 0 C:\workshop\winsas\ C:\workshop\winsas\ prog1\ prog1\crew.sas7bdat 8.0202M0 WIN_PRO Browsing the Data Portion The PRINT procedure displays the data portion of a SAS data set. By default, PROC PRINT displays all observations all variables an Obs column on the left side. 8 11 PROC CONTENTS Output Part 3 Alphabetic List of Variables and Attributes # 6 3 1 7 2 4 5 8 Variable EmpID FirstName HireDate JobCode LastName Location Phone Salary Type Char Char Num Char Char Char Char Num Len 6 32 8 6 32 16 8 8 Format Informat Browsing the Data Portion General form of the PRINT procedure: PROC PRINT DATA=SAS-data-set; PROC PRINT DATA=SAS-data-set; RUN; RUN; DATE9. DATE9. Example: proc print data=work.staff; run; 9 12 2 PROC PRINT Output The SAS System Obs 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 LastName TORRES LANGKAMM SMITH LEISTNER WADE TOMAS WAUGH LEHMANN TRETTHAHN TIETZ O'DONOGHUE WALKER NOROVIITA OESTERBERG LAUFFER TORR WAGSCHAL TOERMOEN First Name JAN SARAH MICHAEL COLIN KIRSTEN HARALD TIM DAGMAR MICHAEL OTTO ART THOMAS JOACHIM ANJA CRAIG JUGDISH NADJA JOCHEN JobTitle Pilot Mechanic Mechanic Mechanic Pilot Pilot Pilot Mechanic Pilot Pilot Mechanic Pilot Mechanic Mechanic Mechanic Pilot Pilot Pilot Salary 50000 80000 40000 36000 85000 105000 70000 64000 100000 45000 52000 95000 78000 80000 40000 45000 77500 65000 13 Valid SAS Names data5mon 5monthsdata data#5 five months data fivemonthsdata 16 SAS Data Set and Variable Names SAS names can be 32 characters long. can be uppercase, lowercase, or mixedcase. must start with a letter or underscore. Subsequent characters can be letters, underscores, or numeric digits. SAS Variable Values There are two types of variables: character contain any value: letters, numbers, special characters, and blanks. Character values are stored with a length of 1 to 32,767 bytes. One byte equals one character. numeric stored as floating point numbers in 8 bytes of storage by default. Eight bytes of floating point storage provide space for 16 or 17 significant digits. You are not restricted to 8 digits. 17 14 Valid SAS Names Select the valid default SAS names. data5mon 5monthsdata data#5 five months data fivemonthsdata SAS Date Values SAS stores date values as numeric values. A SAS date value is stored as the number of days between January 1, 1960, and a specific date. 01JAN1959 -365 display 01/01/1959 15 01JAN1960 store 0 01JAN1961 366 01/01/1960 01/01/1961 18 3 Missing Data Values A value must exist for every variable for each observation. Missing values are valid values. LastName TORRES LANGKAMM SMITH WAGSCHAL TOERMOEN FirstName JAN SARAH MICHAEL NADJA JOCHEN JobTitle Pilot Mechanic Mechanic Pilot Salary 50000 80000 . 77500 65000 Assigning a Libref Regardless of which host operating system you use, you identify SAS data libraries by assigning each a library reference name (libref). libref A character missing value is displayed as a blank. A numeric missing value is displayed as a period. 19 22 SAS Data Libraries A SAS data library is a collection of SAS files that are recognized as a unit by SAS. z/OS (OS/390) A SAS data library is an operating system file. z/OS (OS/390): userid.mysas.files Directory-based A SAS data library is Systems a directory. Windows: UNIX: c:\mysasfiles /users/dept/mysasfiles A SAS data set is a type of SAS file. 20 SAS Data Libraries When you invoke SAS, you automatically have access to a temporary and a permanent SAS data library. SAS Data Library work - temporary library work sasuser - permanent library SAS File SAS File SAS File sasuser st - permanent library st You can create and access your own permanent libraries. 23 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. Assigning 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 <engine-name> 'SAS-data-library'; LIBNAME libref <engine-name> 'SAS-data-library'; 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. 21 24 FILES LIBRARIES 4 Assigning a Libref Examples: libname st `d:\Stat 440\data'; 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. work.employee employee libname ex `d:\Stat 440\mydata.xls'; libname db `c:\demo.mdb'; 25 28 Making the Connection When you submit the LIBNAME statement, a connection is made between a libref in SAS and the physical location of files on your operating system. Windows 'c:\documents\prog1' Browsing a SAS Data Library During an interactive SAS session, the LIBNAME window enables you to investigate the contents of a SAS data library. In the LIBNAME window, you can view a list of all the libraries available during your current SAS session drill down to see all members of a specific library display the descriptor portion of a SAS data set. 26 29 Two-level SAS Filenames Every SAS file has a two-level name: LIBNAME Window: Libraries libref.filename The data set st.sales is a SAS file in the st library. The first name (libref) refers to the library. work sales The second name (filename) refers to the file in the library. st sasuser Issue the LIBNAME command to get this window. Double-click on a library to get a list of its members. 27 30 5 LIBNAME Window: Members SAS vs. Other Terminology Data Library Data Library Data Set Data Set Variable Variable Observation Observation Folder Folder Directory Directory File File Table Table Column Column Field Field Row Row Record Record 31 34 Browsing 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; PROC CONTENTS DATA=libref._ALL_ NODS; RUN; RUN; Lab 2 SAS Libraries Investigating a SAS Data Set with PROC CONTENTS NODS must be used in conjunction with the keyword _ALL_. proc contents data=ia._all_ nods; run; 32 35 PROC CONTENTS Output Partial Output The SAS System The CONTENTS Procedure Directory Libref Engine Physical Name File Name Member Type DATA DATA DATA DATA DATA DATA DATA DATA IA V9 C:\workshop\winsas\ C:\workshop\winsas\prog1 C:\workshop\winsas\ C:\workshop\winsas\prog1 File Size 5120 5120 5120 5120 17408 17408 13312 66560 # 1 2 3 4 5 6 7 8 Name ALLGOALS ALLGOALS2 ALLSALES ALLSALES2 APRTARGET CHICAGO CREW DELAY Last Modified 31Jul01:08:52:34 31Jul01:08:52:38 31Jul01:08:53:28 31Jul01:08:53:46 13Aug01:08:41:42 31Jul01:08:54:38 31Jul01:08:54:44 31Jul01:08:54:46 33 6 ...
View Full Document

This note was uploaded on 10/31/2011 for the course STAT 440 taught by Professor Muyot,m during the Fall '08 term at University of Illinois, Urbana Champaign.

Ask a homework question - tutors are online