BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bernhard
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

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

    View solution in original post

    2 REPLIES 2
    RichardinOz
    Quartz | Level 8

    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

    data_null__
    Jade | Level 19

    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

    sas-innovate-2024.png

    Don't miss out on SAS Innovate - Register now for the FREE Livestream!

    Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

     

    Register now!

    How to Concatenate Values

    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.

    Click image to register for webinarClick image to register for webinar

    Classroom Training Available!

    Select SAS Training centers are offering in-person courses. View upcoming courses for:

    View all other training opportunities.

    Discussion stats
    • 2 replies
    • 538 views
    • 1 like
    • 3 in conversation