## Min and Max Function: Is it mandatory to use a leading „of“ when using min/max with variables

Solved
Occasional Contributor
Posts: 15

# Min and Max Function: Is it mandatory to use a leading „of“ when using min/max with variables

Hello all

My questions applies to the min and max function. In the following I will use the min function for simplification.

The help function on min says „The argument list can consist of a variable list, which is preceded by OF.”

I was wondering whether it is mandatory to use the “of”.

In fact I have been using the min function for a long time never being aware of this. So far I am neither aware that leaving out the min caused problems.

Recently a colleague of mine pointed out to me that he has seen examples where this can cause problems (however, he cannot recall the specific case). Thus he suggested to always use “OF”.

Now this question came up since we have quite some programs that use min in dozens of places and we want to find out whether we should amend the programs or not.

In fact this leads to a few follow up questions. Usually I make use of variable operations as well as the usage of macro variables in min. To give you an example:

%let mvar=2;

data  _null_;

a=9;

b=1;

c=min(a,b,a*&mvar.,a*b+b,a*99,b/&mvar.+1);

put c;

run;

So my question is whether using min in this way will always yield the result I had in mind (which is canonical).

It seems to me that if I was to meticulously apply the min function as described in the help function, I would need to define additional variables. For example already a simple statement such as “c=min(of a*b,b)” results in an error.

Has anyone encountered unexpected behaviour with the min function by not using the "of" (or because of other reasons) like my colleague has?

Regards

Bernhard

Accepted Solutions
Solution
‎03-22-2013 07:25 AM
Posts: 3,852

## Re: Min and Max Function: Is it mandatory to use a leading „of“ when using min/max with variables

Each comma separated argument can be an expression or a variable list as specified by the word OF.

min(1+2,var1-4,var1-var4,of var1-var4);

The third argument is var1 minus var4

The fourth is OF the variable list.

You can see how omitting the word OF when a variable list intended could be a problem.

You could use  "of array reference" which might help to prevent the var1 minus var4 ommitted OF problem

28         data _null_;
29            array var[4] (1:4);
30            x = min(1+2,var1-4,var1-var4,of var1-var4,of var
• );
• 31            put x=;
32            run;

x=-3

All Replies
Super Contributor
Posts: 644

## Re: Min and Max Function: Is it mandatory to use a leading „of“ when using min/max with variables

It is my understanding that OF is only required when the list of parameters is a range of variables, eg min (OF var1-var3).  Prefacing a delimited list of parameters, as in your example, should have no effect because in this instance the OF wold apply only to the first (single) parameter.

Richard

Solution
‎03-22-2013 07:25 AM
Posts: 3,852

## Re: Min and Max Function: Is it mandatory to use a leading „of“ when using min/max with variables

Each comma separated argument can be an expression or a variable list as specified by the word OF.

min(1+2,var1-4,var1-var4,of var1-var4);

The third argument is var1 minus var4

The fourth is OF the variable list.

You can see how omitting the word OF when a variable list intended could be a problem.

You could use  "of array reference" which might help to prevent the var1 minus var4 ommitted OF problem

28         data _null_;
29            array var[4] (1:4);
30            x = min(1+2,var1-4,var1-var4,of var1-var4,of var
• );
• 31            put x=;
32            run;

x=-3
🔒 This topic is solved and locked.