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

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

3 REPLIES 3
stat_sas
Ammonite | Level 13

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

Reeza
Super User

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.
Learner25
Calcite | Level 5

Thank you, Reeza!

I understand how the formula works now 🙂

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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