Fundamentals of Programming in SAS. James Blum

Читать онлайн книгу.

Fundamentals of Programming in SAS - James Blum


Скачать книгу
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 (City)MPG (Highway)
1AcuraMDX$36,9451723
2AcuraRSX Type S 2dr$23,8202431
3AcuraTSX 4dr$26,9902229
4AcuraTL 4dr$33,1952028
5Acura3.5 RL 4dr$43,7551824
6Acura3.5 RL w/Navigation 4dr$46,1001824
7AcuraNSX coupe 2dr manual S$89,7651724
8AudiA4 1.8T 4dr$25,9402231
9AudiA41.8T convertible 2dr$35,9402330
10AudiA4 3.0 4dr$31,8402028

      The SAS log tracks program submissions and generates information during compilation and execution to aid in the debugging process. Most of the information SAS displays in the log (besides repeating the code submission) falls into one of five categories:

       Errors: An error in the SAS log is an indication of a problem that has stopped the compilation or execution process. These may be generated by either syntax or logic errors, see the example in this section for a discussion of the differences in these two error types.

       Warnings: A warning in the SAS log is an indication of something unexpected during compilation or execution that was not sufficient to stop either from occurring. Most warnings are an indication of a logic error, but they can also reflect other events, such as an attempt by the compiler to correct a syntax error.

       Notes: Notes give various information about the submission process, including: process time, records and data set used, locations for file delivery, and other status information. However, some notes actually indicate potential problems during execution. Therefore, reviewing notes is important, and they should not be presumed to be benign. Program 1.4.5, along with others in later chapters, illustrates such an instance.

       Additional Diagnostic Information: Depending on the nature of the note, error, or warning, SAS may transmit additional information to the log to aid in diagnosing the problem.

       Requested Information: Based on various system options and other statements, a SAS program can request additional information be transmitted to the SAS log. The ODS TRACE statement is one such statement covered in Section 1.5. Other statements and options are included in later chapters.

      Program 1.4.5 introduces errors into the code given in Program 1.4.1, with a review of the nature of the mistakes and the log entries corresponding to them shown in Figure 1.4.8. Errors can generally be split into two types: syntax and non-syntax errors. A syntax error occurs when the compiler is unable to recognize a portion of the code as a legal statement, option, or other language element; thus, it is a situation where programming statements do not conform to the rules of the SAS language. A non-syntax error occurs when correct syntax rules are used, but in a manner that leads to an incorrect result (including no result at all). In this book, non-syntax errors are also referred to as logic errors (an abbreviated phrase referring to errors in programming logic). Chapter Note 6 in Section 1.7 provides a further refinement of such error types.

      Program 1.4.5: Program 1.4.1 Revised to Include Errors

      options pagesize=100 linesize=90 number pageno=1 nodate;

      data work.cars;

      set sashelp.cars;

      mpg_combo=0.6*mpg_city+0.4*mpg_highway;

      select(type);

      when(‘Sedan’,’Wagon’) typeB=’Sedan/Wagon’;

      when(‘SUV’,’Truck’) typeB=’SUV/Truck’;

      otherwise typeB=type;

      end;

      label mpg_combo=’Combined MPG’ type2=’Simplified Type’;

      run;

      Title ‘Combined MPG Means’;

      proc sgplot daat=work.cars;

      hbar typeB / response=mpg_combo stat=mean limits=upper;

      where typeB ne ‘Hybrid’;

      run;

      Title ‘MPG Five-Number Summary’;

      Titletwo ‘Across Types’;

      proc means data=car min q1 median q3 max maxdec=1;

      class


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