SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Search||next

Transforming Data with SAS Functions
General Form of SAS Functions


Arguments, Variable Lists, Arrays

All SAS functions are written by specifying the function name followed by the function arguments, enclosed in parentheses.


General form, SAS function:
function-name(argument-1< ,argument-n>);

where argument can be

  • variables  mean(x,y,z)
  • constants  mean(456,502,612,498)
  • expressions  mean(37*2,192/5,mean(22,34,56))
CAUTION: Even if the function does not require arguments, the function name must still be followed by parentheses, for example: function-name().


When a function contains more than one argument, the arguments are usually separated by commas.

          function-name(argument-1,argument-2,argument-n)

However, for some functions, variable lists and arrays can also be used as arguments, as long as the list or the array is preceded by the word OF. You can learn about arrays in the lesson Processing Variables with Arrays.


Example

Here is an example of a function that contains multiple arguments. Notice that the arguments are separated by commas.

     mean(x1,x2,x3)

The arguments for this function can also be written as a variable list.

     mean(of x1-x3)

Or the variables can be referenced by an array.

     mean(of newarray {*})

When specifying function arguments with a variable list or an array, be sure to precede the list or the array with the word OF. If you omit the word OF, the function arguments may not be interpreted as expected. For example, the function below calculates the average of X1 minus X3, not the average of the variables X1, X2, and X3.

     mean(x1-x3)

|next


Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement