The OF Operator with Variable Lists
Definition
The OF operator precedes the arguments of some SAS functions that take variable lists
and arrays as arguments. Here is the general syntax for SAS functions that use the OF
operator:
function-name(OF variable-list) | (OF array-name)
The OF operator is important when used with functions whose arguments are in the form
of a numbered-range list. For example, an argument in the form of a numbered range (x1
– xn) is read in as a range of values only if the list is preceded by the OF operator. If the
same list is not preceded by the OF operator and it is used with the SUM function, the (-)
character is treated as a subtraction sign. The function returns the difference between the
variables rather than the sum of the range of values.
In the following example, arguments are passed in as numbered range lists, both with
and without the use of the OF operator. The first SUM function returns T=20 and the
second SUM function returns
T2=60.
data _null_;
x1=30; x2=20; x3=10;
T=sum(x1-x3);
T2=sum(OF x1-x3);
put T=; /*returns the difference between x1 and x3.*/
Put T2=; /*returns the sum of the variable values from x1 to x3 (inclusive)*/
run;
Note: If you pass in an argument that contains an operation such as subtraction or
addition on data that contains missing values, SAS returns a missing value and no
calculation is made.
You can also use the OF operator to pass array names into functions as shown here:
varA=mean(of array-name[*]);
For more information about using the OF operator with arrays, see “Using the OF
Operator with Temporary Arrays” in SAS Functions and CALL Routines: Reference.
Multiple Variable Lists
The OF operator is also used to distinguish one variable list from another when multiple
ranged lists are used as arguments in functions. If more than one ranged variable list is
used, either the entire list is preceded by the OF operator and the lists are separated by
spaces or each list is preceded by the OF operator and the lists are separated by commas,
as shown in the following examples:
T=sum(OF x1-x3 y1-y3 z1-z3)
Or
T=sum(OF x1–x3, OF y1–y3, OF z1–z3)
For more information about the different types of variable lists used in SAS, see “SAS
Variable Lists” on page 49.
For a list of SAS functions that use the OF operator, see Table 11.1 on page 181.
The following table shows the types of SAS variable lists that are valid with the OF
operator:
SAS Variable Lists 51