Fundamentals of Programming in SAS. James Blum

Чтение книги онлайн.

Читать онлайн книгу Fundamentals of Programming in SAS - James Blum страница 7

Автор:
Жанр:
Серия:
Издательство:
Fundamentals of Programming in SAS - James Blum

Скачать книгу

in the Sashelp Library in the Windowing Environment

Figure 1.4.4: Accessing the Cars Data Set in the Sashelp Library in the Windowing Environment

      Figure 1.4.5 shows how to open the Cars data set in a SAS University Edition session, revealing several differences in the library navigation and the data view, which opens in a separate tab in the University Edition session.

      Figure 1.4.5: Accessing the Cars Data Set in the Sashelp Library in University Edition

Figure 1.4.5: Accessing the Cars Data Set in the Sashelp Library in University Edition

      In the SAS windowing environment, options for the data view are driven by menus and toolbar buttons for the active window, while in SAS University Edition, each data set tab contains a set of buttons and menus in its toolbar. As part of this tab, SAS University Edition also offers boxes to select a subset of variables and gives properties for each variable as it is selected. Such changes are possible in the SAS windowing environment as well, but are menu-driven. For more information, see the SAS Documentation for the chosen environment.

      Another major difference between the two data views is that the ViewTable in the SAS windowing environment has active control over the data set selected. The view in SAS University Edition is generated when the data set is opened, or re-generated if new options are selected, and control of the data set is released. For further detail on the implications of these differences, see Chapter Note 4 in Section 1.7.

      Though there are ultimately several different forms of SAS libraries, the most basic simply assigns a library reference (or libref) to a folder which the SAS session can access. A library can be assigned in a program via the LIBNAME statement or through other tools available in the SAS windowing environment or SAS University Edition. In order to use this book, it is essential to assign library references to the data sets downloaded from the author web pages. Figures 1.4.6 and 1.4.7 show an assignment of a library named BookData to an assumed location. The path must be set to the actual location of the downloaded files, and the choice of library name must follow the naming conventions given previously in Program 1.4.3, with the additional restriction that the library reference is limited to 8 characters.

      Figure 1.4.6: Assigning a Library in the SAS Windowing Environment

Figure 1.4.6: Assigning a Library in the SAS Windowing Environment

      Figure 1.4.7: Assigning a Library in SAS University Edition

Figure 1.4.7: Assigning a Library in SAS University Edition

      Submitting the following LIBNAME statement is equivalent to the assignments shown in the Figures 1.4.6 and 1.4.7, except for the fact that the assigned library is not re-created at start-up of the next session.

      libname bookdata ‘C:\Book Data’;

      Any of these assignments creates what is known as a permanent library, meaning that data sets and other files stored there remain in place until an explicit modification is made to them. Temporary libraries are expunged when the SAS session ends—in the SAS Windowing environment, Work is a temporary library; in SAS University Edition, Work and Webwork are temporary.

      The PRINT and CONTENTS procedures provide information about data and metadata as program output. Program and Output 1.4.4 provide a demonstration of their use.

      Program 1.4.4: Using the CONTENTS and PRINT Procedures to Display Metadata and Data

      proc contents data=sashelp.cars;

      run;

      proc print data=sashelp.cars(obs=10) label;

      var make model msrp mpg_city mpg_highway;

      run;

       The CONTENTS procedure output shows a variety of metadata, including the number of variables, number of observations, and the full set of variables and their attributes. Adding the option VARNUM to the PROC CONTENTS statement reorders the variable attribute table in column order—default display is alphabetical by variable name. The keyword _ALL_ can be used in place of the data set name, in this instance, the output contains a full list of all library members followed by metadata for each data set in the library.

       The PRINT procedure directs the data portion of the selected data set to all active output destinations. By default, PROC PRINT displays variable names as column headers, the LABEL option changes these to the variable labels (when present). Display of labels is also controlled by the LABEL/NOLABEL system options, see Chapter Note 5 in Section 1.7 for additional details.

       Default behavior of the PRINT procedure is to output all rows and columns in the current data order. The VAR statement selects the set of columns and their order for display.

      Output 1.4.4A: Output from PROC CONTENTS for Sashelp.Cars

Data Set NameSASHELP.CARSObservations428
Member TypeDATAVariables15
EngineV9Indexes0
CreatedLocal Information DiffersObservation Length152
Last ModifiedLocal Information DiffersDeleted Observations0
ProtectionCompressedNO
Data Set TypeSortedYES
Label2004 Car Data
Data RepresentationWINDOWS_64
Encodingus-ascii ASCII (ANSI)
Engine/Host Dependent Information
Data Set Page Size65536
Number of Data Set Pages2
First Data Page1
Max Obs per Page430
Obs in First Data Page413
Number of Data Set Repairs0
ExtendObsCounterYES
FilenameLocal Information Differs
Release Created9.0401M4
Host CreatedX64_SR12R2
Owner NameBUILTIN\Administrators
File Size192KB
File Size (bytes)196608
Alphabetic List of Variables and Attributes
#VariableTypeLenFormatLabel
9CylindersNum8
5DriveTrainChar5
8EngineSizeNum8Engine Size (L)
10HorsepowerNum8
7InvoiceNum8DOLLAR8.
15LengthNum8Length (IN)
11MPG_CityNum8MPG (City)
12MPG_HighwayNum8MPG (Highway)
6MSRPNum8DOLLAR8.
1MakeChar13
2ModelChar40
4OriginChar6
3TypeChar8
13WeightNum8Weight (LBS)
14WheelbaseNum8Wheelbase (IN)
Sort Information
SortedbyMake Type
ValidatedYES
Character SetANSI

      Output 1.4.4B: Output from PROC PRINT (First 10 Rows) for Sashelp.Cars

ObsMakeModelMSRPMPG

Скачать книгу