ERROR Statement


Sets _ERROR_ to 1 and, optionally , writes a message to the SAS log

Valid: in a DATA step

Category: Action

Type: Executable

Syntax

ERROR < message >;

Without Arguments

Using ERROR without an argument sets the automatic variable _ERROR_ to 1 without printing any message in the log.

Arguments

message

  • writes a message to the log.

  • Tip: Message can include character literals ( enclosed in quotation marks), variable names , formats, and pointer controls.

Details

The ERROR statement sets the automatic variable _ERROR_ to 1 and, optionally, writes a message that you specify to the SAS log. When _ERROR_ = 1, SAS writes the data lines that correspond to the current observation in the SAS log.

Using ERROR is equivalent to using these statements in combination:

  • an assignment statement setting _ERROR_ to 1

  • a FILE LOG statement

  • a PUT statement (if you specify a message)

  • another FILE statement resetting FILE to any previously specified setting.

Examples

In the following examples, SAS writes the error message and the variable name and value to the log for each observation that satisfies the condition in the IF-THEN statement.

  • In this example, the ERROR statement automatically resets the FILE statement specification to the previously specified setting.

     file  file-specification  ;     if type='teen' & age > 19 then        error 'type and age don"t match ' age=; 
  • This example uses a series of statements to produce the same results.

     file  file-specification  ;     if type='teen' & age > 19 then        do;           file log;           put 'type and age don"t match ' age=;           _error_=1;           file  file-specification  ;        end; 

See Also

Statement:

  • PUT Statement on page 1342




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net