Validating Query Syntax

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:
  • the NOEXEC option in the PROC SQL statement
  • the VALIDATE keyword before a SELECT statement.
Consider how you specify the NOEXEC option and the VALIDATE keyword, and examine the minor differences between them.

Using the NOEXEC Option

The NOEXEC option is specified in the following PROC SQL statement:
proc sql noexec;
   select empid, jobcode, salary
      from sasuser.payrollmaster
      where jobcode contains 'NA'
      order by salary;
If the query is valid and all referenced columns and tables exist, the SAS log displays the following message.
Table 2.5 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 invoke the NOEXEC option, SAS checks the syntax of all queries in that PROC SQL step for accuracy but does not execute them.

Using the VALIDATE Keyword

You specify the VALIDATE keyword just before a SELECT statement; it is not used with any other PROC SQL statement.
We will modify the preceding PROC SQL query by using the VALIDATE keyword instead of the NOEXEC option:
proc sql;
   validate
   select empid, jobcode, salary
      from sasuser.payrollmaster
      where jobcode contains 'NA'
      order by salary;
Note: Note that the VALIDATE keyword is not followed by a semicolon.
If the query is valid, the SAS log displays the following message.
Table 2.6 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 only 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.
..................Content has been hidden....................

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