Previous Page | Next Page

Functions and CALL Routines

Syntax


Syntax of Functions

The syntax of a function has one of the following forms:

function-name (argument-1<, ...argument-n>)
function-name (OF variable-list)
function-name (<argument | OF variable-list | OF array-name[*]><..., <argument | OF variable-list | OF array-name[*]>>)
where
function-name

names the function.

argument

can be a variable name, constant, or any SAS expression, including another function. The number and type of arguments that SAS allows are described with individual functions. Multiple arguments are separated by a comma.

Tip: If the value of an argument is invalid (for example, missing or outside the prescribed range), SAS writes a note to the log indicating that the argument is invalid, sets _ERROR_ to 1, and sets the result to a missing value.
Examples:
  • x=max(cash,credit);
  • x=sqrt(1500);
  • NewCity=left(upcase(City));
  • x=min(YearTemperature-July,YearTemperature-Dec);
  • s=repeat('----+',16);
  • x=min((enroll-drop),(enroll-fail));
  • dollars=int(cash);
  • if sum(cash,credit)>1000 then
       put 'Goal reached';
variable-list

can be any form of a SAS variable list, including individual variable names. If more than one variable list appears, separate them with a space or with a comma and another OF.

Examples:
  • a=sum(of x  y  z);
  • The following two examples are equivalent.

    • a=sum(of x1-x10 y1-y10 z1-z10);
      a=sum(of x1-x10, of y1-y10, of z1-z10);
  • z=sum(of y1-y10);
  • z=msplint(x0,5,of x1-x5,of y1-y5,-2,2);
array-name{*}

names a currently defined array. Specifying an array with an asterisk as a subscript causes SAS to treat each element of the array as a separate argument.

The OF operator has been extended to accept temporary arrays. You can use temporary arrays in OF lists for most SAS functions just as you can use regular variable arrays, but there are some restrictions. For a list of these restrictions, see Using the OF Operator with Temporary Arrays.


Syntax of CALL Routines

The syntax of a CALL routine has one of the following forms:

CALL routine-name (argument-1<, ...argument-n>);
CALL routine-name (OF variable-list);
CALL routine-name (argument-1 | OF variable-list-1 <, ...argument-n | OF variable-list-n>);

where

routine-name

names a SAS CALL routine.

argument

can be a variable name, a constant, any SAS expression, an external module name, an array reference, or a function. Multiple arguments are separated by a comma. The number and type of arguments that are allowed are described with individual CALL routines in the dictionary section.

Examples:
  • call prxsubstr(prx,string,position);
  • call prxchange('/old/new',1+k,trim(string),result,length);
  • call set(dsid);
  • call ranbin(Seed_1,n,p,X1);
  • call label(abc{j},lab);
  • call cats(result,'abc',123);
variable-list

can be any form of a SAS variable list, including variable names. If more than one variable list appears, separate them with a space or with a comma and another OF.

Examples:
  • call cats(inventory, of y1-y15, of z1-z15);
  • call catt(of item17-item23 pack17-pack23);

Previous Page | Next Page | Top of Page