Author: Doug Hemken

# Showing SAS errors

#### Doug Hemken

#### Aug 2022

SAS does not always exit with an error when it encounters problems, but when it does, you should see the log in your document instead of the code.

## First, set up your SAS engine configuration.

    library(SASmarkdown)

## A Semantic Error

Semantic errors (typos etc.) cause SAS to return an error status when SAS finishes. This will automatically cause SASmarkdown to switch from the `sas` engine to the `saslog` engine.

In this example, trying to use WORK data without any data there, SAS produces an ERROR, and no output is produced.)

    ```{sas procmeans}
    proc means data=class;
    run;
    ```

Which produces:

    2          proc means data=class;
    WARNING: The Base SAS Software product with which MEANS is associated will
             be expiring soon, and is currently in warning mode to indicate
             this upcoming expiration. Please run PROC SETINIT to obtain more
             information on your warning period.
    ERROR: File WORK.CLASS.DATA does not exist.
    3          run;

    NOTE: The SAS System stopped processing this step because of errors.
    NOTE: PROCEDURE MEANS used (Total process time):
          real time           0.03 seconds
          cpu time            0.01 seconds

    ERROR: Errors printed on page 1.

## An Execution Error.

Division by zero produces error flags within the DATA step, but does not cause SAS to return an error code when it finishes. The `sas` engine gives us the usual output.

To see the DATA step ERROR, switch to the `saslog` engine.

    ```{saslog divzero}

    *--- sas code ---;

    ```

Producing both the log and the PROC PRINT output.

    data class;
        set sashelp.class(obs=5);
        age0 = age/0;
        keep age age0;
        run;

    proc print data=class;
    run;

                                Obs    Age    age0

                                 1      14      .
                                 2      13      .
                                 3      13      .
                                 4      14      .
                                 5      14      .

## Replicate in HTML

For a semantic error, which produces no output tables or graphs, the sas and sashtml engines give us the same result.

    6          proc means data=class;
    ERROR: File WORK.CLASS.DATA does not exist.
    7          run;

    NOTE: The SAS System stopped processing this step because of errors.
    NOTE: PROCEDURE MEANS used (Total process time):
          real time           0.00 seconds
          cpu time            0.01 seconds

    ERROR: Errors printed on page 1.

For an execution error, using the sashtmllog engine, we see both the DATA step errors and the HTML output.

    6          proc means data=class;
    ERROR: File WORK.CLASS.DATA does not exist.
    7          run;

    NOTE: The SAS System stopped processing this step because of errors.
    NOTE: PROCEDURE MEANS used (Total process time):
          real time           0.00 seconds
          cpu time            0.01 seconds

    ERROR: Errors printed on page 1.