Fundamentals of Programming in SAS. James Blum

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

Fundamentals of Programming in SAS - James Blum


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

      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 1.5.1: Using ODS TRACE to Track Output

      ods trace on;

      proc contents data=sashelp.cars;

      run;

      proc contents data=sashelp.cars varnum;

      run;

       There are many ODS statements available in SAS, some act globally—they remain in effect until another statement alters that effect—while others act locally—for the execution of the current or next procedure. The TRACE is a recording of all output objects generated by the code execution. ON delivers this information to the SAS log; OFF suppresses it. The effect of ODS TRACE is global, the ON or OFF condition only changes with a submission of a new ODS TRACE statement that makes the change. The typical default at the invocation of a SAS session is OFF.

       The VARNUM option in PROC CONTENTS rearranges the table showing the variable information from alphabetical order to position order. This also represents a change in the name of the table as indicated in the TRACE information shown in the log.

      Log 1.5.1A: Using ODS TRACE to Track Output

      74 ods trace on;

      75 proc contents data=sashelp.cars;

      76 run;

      Output Added:

      -------------

      Name: Attributes

      Label: Attributes

      Template: Base.Contents.Attributes

      Path: Contents.DataSet.Attributes

      -------------

      Output Added:

      -------------

      Name: EngineHost

      Label: Engine/Host Information

      Template: Base.Contents.EngineHost

      Path: Contents.DataSet.EngineHost

      -------------

      Output Added:

      -------------

      Name: Variables

      Label: Variables

      Template: Base.Contents.Variables

      Path: Contents.DataSet.Variables

      -------------

      Output Added:

      -------------

      Name: Sortedby

      Label: Sortedby

      Template: Base.Contents.Sortedby

      Path: Contents.DataSet.Sortedby

      -------------

      NOTE: PROCEDURE CONTENTS used (Total process time):

       real time 0.29 seconds

       cpu time 0.20 seconds

      Log 1.5.1B: Using ODS TRACE to Track Output

      78 proc contents data=sashelp.cars varnum;

      79 run;

      Output Added:

      -------------

      Name: Attributes

      Label: Attributes

      Template: Base.Contents.Attributes

      Path: Contents.DataSet.Attributes

      -------------

      Output Added:

      -------------

      Name: EngineHost

      Label: Engine/Host Information

      Template: Base.Contents.EngineHost

      Path: Contents.DataSet.EngineHost

      -------------

      Output Added:

      -------------

      Name: Position

      Label: Varnum

      Template: Base.Contents.Position

      Path: Contents.DataSet.Position

      -------------

      Output Added:

      -------------

      Name: Sortedby

      Label: Sortedby

      Template: Base.Contents.Sortedby

      Path: Contents.DataSet.Sortedby

      -------------

      NOTE: PROCEDURE CONTENTS used (Total process time):

       real time 0.13 seconds

       cpu time 0.07 seconds

      Each table generated by PROC CONTENTS has a name and a label; sometimes these are the same. Labels are free-form, while names follow the SAS naming conventions described earlier which are revisited in Section 1.6.2. The SAS Documentation also includes lists of ODS table names for each procedure, along with information about which are generated as default procedure output and which tables are generated as the result of including specific options. From the traces shown in Logs


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