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
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
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
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
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.