## Max and Min calculation

Solved
Occasional Contributor
Posts: 17

# Max and Min calculation

Dear SAS Community,

This is probably an easy question, however, I have trouble making it work.  I just want to find out either a maximum or minimum number from two numbers that have unique values.   For an example, I get errors when writing below:

data Test;
q1=5;
q2=10;
z=Largest(q1, q2);
run;

Accepted Solutions
Solution
‎05-08-2016 02:37 PM
Super User
Posts: 23,700

## Re: Max and Min calculation

Are you expecting to find the lowest value in the row or in the column?

If row the command can be MIN/MAX as in your subject line.

You can use the LARGEST function but the first parameter is what order your looking for, 1 is the maximum and 2 is the second highest. If you only have 2 values then that would correspond to max/min.

``````x = min(q1, q2);
y = max(q1, q2);

x_large = Largest(1, q1, q2);
y_large = Largest(2, q1, q2);
``````

See the doc for LARGEST()

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002154862.htm

``````
LARGEST (k, value-1<, value-2 ...>)

Arguments
k
is a numeric constant, variable, or expression that specifies which value to return.

value
specifies the value of a numeric constant, variable, or expression to be processed.``````

All Replies
Posts: 1,270

## Re: Max and Min calculation

data Test;
q1=5;
q2=10;
z=Largest(1,q1, q2);
run;

Solution
‎05-08-2016 02:37 PM
Super User
Posts: 23,700

## Re: Max and Min calculation

Are you expecting to find the lowest value in the row or in the column?

If row the command can be MIN/MAX as in your subject line.

You can use the LARGEST function but the first parameter is what order your looking for, 1 is the maximum and 2 is the second highest. If you only have 2 values then that would correspond to max/min.

``````x = min(q1, q2);
y = max(q1, q2);

x_large = Largest(1, q1, q2);
y_large = Largest(2, q1, q2);
``````

See the doc for LARGEST()

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002154862.htm

``````
LARGEST (k, value-1<, value-2 ...>)

Arguments
k
is a numeric constant, variable, or expression that specifies which value to return.

value
specifies the value of a numeric constant, variable, or expression to be processed.``````
Occasional Contributor
Posts: 17

## Re: Max and Min calculation

Thank you, Reeza!

I understand how the formula works now

🔒 This topic is solved and locked.