Types Of Error In SAS : Syntax Error, Execution Time Error, Data Error,Semantic Error

Many of us are familiar with Errors in SAS and most of the time we have seen the classification of errors in SAS log.

As per the log classification in SAS, There are four type of errors in SAS :

1. SYNTAX ERROR      2. EXECUTION TIME ERROR    3. DATA ERROR     4. SEMANTIC ERROR

1. SYNTAX ERROR : We can have such types of errors whenever our programming statements or codes does not follow the SAS language coding rules. SAS detects SYNTAX Error at COMPILE TIME / STAGE. Syntax errors could be due to the following reasons :

  • Any keyword which is not spelled correctly (Misspelled keyword)

  • Missing or Invalid punctuation

  • Invalid statements or data set options

Quotations marks not used properly (Unmatched)

2. EXECUTION TIME ERROR : Whenever SAS executes a program which processes data, during the processing of data value if any error occurs that is known as EXECUTION TIME ERROR. Most of the execution time errors just gives warning messages or notes in SAS log but These errors allow the program to continue the execution of data. We can identify execution time error usually by location which would be given as line and column numbers in a SAS note or SAS error message. Execution time error could be due to following reasons:


  • Any mathematical operation which is not legal ( division by zero )

  • Any argument to function which is not legal

  • For BY group processing, when observations are not in proper order

  • While referring to a member of an array which does not exist

  • Open and close error (for brackets and inverted commas) on SAS data sets and other files like INFILE

  • Any INPUT statements which do not match with the cards / datalines 

3. DATA ERROR : We can have such type of errors in SAS, whenever any data values are not as per the SAS statement which we have specified in our SAS program. Suppose we have defined a variable as a numeric but we are passing some data values which are character then SAS gives an error that would be known as DATA ERROR. Data errors occurs during the program execution but these errors allow the program to continue the execution of data and does the following things:

  • It prints the obs under the rule line

  • In the SAS log, It writes an invalid data notes with line number

  • It sets the automatic variable _ERROR_ to for current observation

  • In SAS log, it prints the input line and column number which contain invalid data

4. SEMANTIC ERRORS : We can have such type of error in SAS, whenever our programming statements or codes are up to the mark means any SAS statement is correct but any element is not valid for that specific usage. SAS detects SEMANTIC ERRORS at COMPILE TIME / STAGE. Whenever SAS finds any semantic error in program SAS goes for syntax check mode. Semantic errors could be due to the following reasons :

  • Defining or using a numeric variable where only a character variable is applicable

  • For Array, when we use any illegal reference for it

  • Whenever we do not specify correct number of arguments  for any SAS Functions

Ex:  Suppose we are using a libname for a dataset without assigning it prior, for semantic error, libname statement is valid but as it is not specified previously so it would through an error.

3 comments: