Functions and CALL Routines

Syntax


Syntax of Functions

The syntax of a function is

function-name (argument-1<, ...argument-n>)
function-name (OF variable-list)
function-name (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 kind 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);
array-name{*}

names a currently defined array. Specifying an array in this way causes SAS to treat the array as a list of the variables instead of processing only one element of the array at a time.

Examples:
  • array y{10} y1-y10;
    x=sum(of y{*});

Syntax of CALL Routines

The syntax of a CALL routine is

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 kind of arguments that are allowed are described with individual CALL routines in the dictionary section.

Examples:
  • call rxsubstr(rx,string,position);
  • call set(dsid);
  • call ranbin(Seed_1,n,p,X1);
  • call label(abc{j},lab);
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);

space
Previous Page | Next Page | Top of Page