Fundamentals of Programming in SAS. James Blum

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

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

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

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

Type S 2dr$23,82024313AcuraTSX 4dr$26,99022294AcuraTL 4dr$33,19520285Acura3.5 RL 4dr$43,75518246Acura3.5 RL w/Navigation 4dr$46,10018247AcuraNSX coupe 2dr manual S$89,76517248AudiA4 1.8T 4dr$25,94022319AudiA41.8T convertible 2dr$35,940233010AudiA4 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 typeB;

      var mpg:;

      run;

       This is a non-syntax error; the variable name Type2 is legal and is used correctly in the LABEL statement. However, no variable named Type2 has been defined in the data set.

       This is a syntax error, daat is not a legal option in this PROC statement.

       This is a syntax error, titletwo is not a legal statement name.

       This is a non-syntax error; the syntax is legal and directs the procedure to use a data set named Car in the Work library; however, no such data set exists.

      Figure 1.4.8A: Checking the SAS Log for Program 1.4.4, First Page

Figure 1.4.8A: Checking the SAS Log for Program 1.4.4, First Page

      Figure 1.4.8B: Checking the SAS Log for Program 1.4.4, Second Page

Figure 1.4.8B: Checking the SAS Log for Program 1.4.4, Second Page

      Figure 1.4.8C: Checking the SAS Log for Program 1.4.4, Third Page

Figure 1.4.8C: Checking the SAS Log for Program 1.4.4, Third Page

      The value of a complete review of the SAS log cannot be overstated. Programmers often believe the code is correct if it produces output or if the log does not contain errors or warnings, a practice that can leave undetected problems in the code and the results.

      Upon invocation of the SAS session, the log also displays notes, warnings, and errors as appropriate relating to the establishment of the SAS session. See the SAS Documentation for information about these messages.

      The sample code presented in this section introduces SAS programming concepts that are important for working effectively in a SAS session and for re-creating samples shown in subsequent sections of this book. Delivery of output to various destinations, naming output files, and choosing the location where they are stored are included. Some differences in appearance that may arise between destinations are also discussed.

      Program 1.5.1 revisits the CONTENTS procedure shown in Program 1.4.4, which generates output that is arranged and displayed in four tables. An Output Delivery System (ODS) statement, ODS TRACE ON, is supplied to deliver information to the log about all output objects generated.

      Program

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