Validating Query Syntax

A Brief Overview

When you are building a PROC SQL query, you might find it more efficient to check your query without actually executing it. To verify the syntax and the existence of columns and tables that are referenced in the query without executing the query, use either of the following combinations:
  • the NOEXEC option in the PROC SQL statement
  • the VALIDATE keyword before a SELECT statement

Example: Using the NOEXEC Option

The NOEXEC option is specified in the following PROC SQL statement:
proc sql noexec;
   select empid, jobcode, salary
      from certadv.payrollmaster
      where jobcode contains 'NA'
      order by salary;
quit;
If the query is valid and all referenced columns and tables exist, the SAS log displays the following message.
Log 1.6 SAS Log
NOTE: Statement not executed due to NOEXEC option.
Or, if there are any errors in the query, SAS displays the standard error messages in the log.
When you use the NOEXEC option, SAS checks the syntax of all queries in that PROC SQL step for accuracy but does not execute them.

Example: Using the VALIDATE Keyword

You specify the VALIDATE keyword just before a SELECT statement; it is not used with any other PROC SQL statement.
You can modify the preceding PROC SQL query by using the VALIDATE keyword instead of the NOEXEC option:
proc sql;
   validate
   select empid, jobcode, salary
      from certadv.payrollmaster
      where jobcode contains 'NA'
      order by salary;
quit;
Note: The VALIDATE keyword is not followed by a semicolon.
If the query is valid, the SAS log displays the following message.
Log 1.7 SAS Log
NOTE: PROC SQL statement has valid syntax.
If there are errors in the query, SAS displays the standard error messages in the log.
The main difference between the VALIDATE keyword and the NOEXEC option is that the VALIDATE keyword affects the SELECT statement that immediately follows it, whereas the NOEXEC option applies to all queries in the PROC SQL step. If you are working with a PROC SQL query that contains multiple SELECT statements, the VALIDATE keyword must be specified before each SELECT statement that you want to check.
Last updated: October 16, 2019
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset