Fundamentals of Programming in SAS. James Blum
Чтение книги онлайн.
Читать онлайн книгу Fundamentals of Programming in SAS - James Blum страница 7
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
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.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 Name | SASHELP.CARS | Observations | 428 |
Member Type | DATA | Variables | 15 |
Engine | V9 | Indexes | 0 |
Created | Local Information Differs | Observation Length | 152 |
Last Modified | Local Information Differs | Deleted Observations | 0 |
Protection | Compressed | NO | |
Data Set Type | Sorted | YES | |
Label | 2004 Car Data | ||
Data Representation | WINDOWS_64 | ||
Encoding | us-ascii ASCII (ANSI) |
Engine/Host Dependent Information | |
Data Set Page Size | 65536 |
Number of Data Set Pages | 2 |
First Data Page | 1 |
Max Obs per Page | 430 |
Obs in First Data Page | 413 |
Number of Data Set Repairs | 0 |
ExtendObsCounter | YES |
Filename | Local Information Differs |
Release Created | 9.0401M4 |
Host Created | X64_SR12R2 |
Owner Name | BUILTIN\Administrators |
File Size | 192KB |
File Size (bytes) | 196608 |
Alphabetic List of Variables and Attributes | |||||
# | Variable | Type | Len | Format | Label |
9 | Cylinders | Num | 8 | ||
5 | DriveTrain | Char | 5 | ||
8 | EngineSize | Num | 8 | Engine Size (L) | |
10 | Horsepower | Num | 8 | ||
7 | Invoice | Num | 8 | DOLLAR8. | |
15 | Length | Num | 8 | Length (IN) | |
11 | MPG_City | Num | 8 | MPG (City) | |
12 | MPG_Highway | Num | 8 | MPG (Highway) | |
6 | MSRP | Num | 8 | DOLLAR8. | |
1 | Make | Char | 13 | ||
2 | Model | Char | 40 | ||
4 | Origin | Char | 6 | ||
3 | Type | Char | 8 | ||
13 | Weight | Num | 8 | Weight (LBS) | |
14 | Wheelbase | Num | 8 | Wheelbase (IN) |
Sort Information | |
Sortedby | Make Type |
Validated | YES |
Character Set | ANSI |
Output 1.4.4B: Output from PROC PRINT (First 10 Rows) for Sashelp.Cars
Obs | Make | Model | MSRP | MPG
|