SAS - Functions


Advertisements


SAS has a wide variety of in built functions which help in analysing and processing the data. These functions are used as part of the DATA statements. They take the data variables as arguments and return the result which is stored into another variable. Depending on the type of function, the number of arguments it takes can vary. Soem functions accept zero arguments while some other accept fixed number of variables. Below is a list of types of functions SAS provides.

Syntax

The general syntax for using a function in SAS si as below.

FUNCTIONNAME(argument1, argument2...argumentn)

Here the argument can be a constant, variable, expression or another function.

Function Categories

Depending on their usage, the functions in SAS are categorised as below.

    Mathematical Date and Time Character Truncation Financial Access Previous Observations (Lags) Special Use and Miscellaneous

Mathematical Functions

These are the functions used to apply some mathematical calculations on the variable values.

Examples

The below SAS program shows the use of some important mathematical functions.

data Math_functions;
 v1=21; v2=42; v3=13; v4=10; v5=29;
 /*Get Maximum value */
max_val = MAX(v1,v2,v3,v4,v5);

/*Get Minimum value */
min_val = MIN (v1,v2,v3,v4,v5);

/*Get Median value */
med_val = MEDIAN (v1,v2,v3,v4,v5);

/*Get a random number */
rand_val = RANUNI(0);

/*Get Square root of sum of the values */
SR_val= SQRT(sum(v1,v2,v3,v4,v5));

proc print data = Math_functions noobs;
run;

Whent he above code is run, we get the following output:

math_funcs_result