Chapter Contents

Previous

Next
SAS Component Language: Reference

Expressions

An SCL expression can be a sequence of operands and operators forming a set of instructions that are performed to produce a result value, or it can be a single variable name, constant, or function. Operands can be variable names or constants, and they can be numeric, character, or both. Operators can be symbols that request a comparison, a logical operation, or an arithmetic calculation. Operators can also be SAS functions and grouping parentheses.

Expressions are used for calculating and assigning new values, for conditional processing, and for transforming variables. These examples show SAS expressions:

SCL expressions can resolve to numeric, character, or Boolean values. In addition, a numeric expression that contains no logical operators can serve as a Boolean expression.


Boolean Numeric Expressions

In SCL programs, any numeric value other than 0 or missing is true, whereas a value of 0 or missing is false. Therefore, a numeric variable or expression can stand alone in a condition. If the value is a number other than 0 or missing, then the condition is true; if the value is 0 or missing, then the condition is false.

A numeric expression can be simply a numeric constant, as follows:

if 5 then do;
The numeric value returned by a function is also a valid numeric expression:
if index(address,'Avenue') then do;


Using Functions in Expressions

You can use functions almost any place in an SCL program statement where you can use variable names or literal values. For example, the following example shows a way to perform an operation (in this case, the FETCH function) and take an action, based on the value of the return code from the function:

rc=fetch(dsid);
      /* The return code -1 means the  */
      /* end of the file was reached.  */
   if (rc=-1) then
      do;
      ...SCL statements to handle the 
      end-of-file condition... 
      end;

To eliminate the variable for the return code, you can use the function directly in the IF statement's expression, as shown in the following example:

if (fetch(dsid)=-1) then
      do;
       ...SCL statements to handle the
       end-of-file condition...
      end;

In this case, the FETCH function is executed, and then the IF expression evaluates the return code to determine whether to perform the conditional action.

As long as you do not need the value of the function's return code for any other processing, the latter form is more efficient because it eliminates the unnecessary variable assignment.


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.