FCMP Procedure

FUNCTION Statement

Specifies a subroutine declaration for a routine that returns a value.
Creating a Function and Calling the Function from a DATA Step

Creating a CALL Routine and a Function

Using Numeric Data in the FUNCTION Statement

Using Character Data in the FUNCTION Statement

Using Variable Arguments with an Array

Using GTL with User-Defined Functions

Syntax

FUNCTION function-name(argument-1, ..., argument-n) <VARARGS> <$> <length>
<KIND | GROUP='string'>;
... more-program-statements ...
RETURN (expression);
ENDSUB;

Required Arguments

function-name
specifies the name of the function.
argument
specifies one or more arguments for the function. You specify character arguments by placing a dollar sign ($) after the argument name. In the following example, function myfunct(arg1, arg2 $, arg3, arg4 $); arg1 and arg3 are numeric arguments, and arg2 and arg4 are character arguments.
expression
specifies the value that is returned from the function.

Optional Arguments

VARARGS
specifies that the function supports a variable number of arguments. If you specify VARARGS, then the last argument in the function must be an array.
$
specifies that the function returns a character value. If $ is not specified, the function returns a numeric value.
length
specifies the length of a character value.
Default:8
KIND='string'
GROUP='string'
specifies a collection of items that have specific attributes.

Details

The FUNCTION statement is a special case of the subroutine declaration that returns a value. You do not use a CALL statement to call a function. The definition of a function begins with the FUNCTION statement and ends with an ENDSUB statement.