DATA Step, Macro, Functions and more

Highest value between 4 variables

Reply
Occasional Contributor
Posts: 7

Highest value between 4 variables

Hello,

 

I have four variables A, B, C and D. For each row these variables have integer values.

 

I would like to know how to get the value of the highest variable between the 4. FOr example:

A       B      C      D

12    11     18     7

The result should be 18.

 

I want to do this with proc sql.

 

Thanks for help.

PROC Star
Posts: 740

Re: Highest value between 4 variables

Like this?

 

data have;
	input A B C D;
	datalines;
	12
	11
	18
	7
	;

proc sql;
	create table want as
	select *
	      ,max(A,B,C,D) as highest_value
	from have;
quit;
Super User
Super User
Posts: 7,948

Re: Highest value between 4 variables

With your data:

data want;
  a=12; b=11; c=18; d=7;
  max=max(a,b,c,d);
  /* or */
  mx=max(of _numeric_);
run;

The second will take all numeric variables.

Ask a Question
Discussion stats
  • 2 replies
  • 73 views
  • 3 likes
  • 3 in conversation