BookmarkSubscribeRSS Feed
indox
Obsidian | Level 7

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.

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

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;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1357 views
  • 3 likes
  • 3 in conversation