Max and Min calculation

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

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;

Thank you for your help!

 


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

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.

View solution in original post


All Replies
Trusted Advisor
Posts: 1,228

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: 19,057

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 Smiley Happy

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 315 views
  • 0 likes
  • 3 in conversation