BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Gick
Pyrite | Level 9
data try_data;
input V1 V2 V3;
datalines;
3 1 1 
2 3 2 
1 1 2 
0 2 3 
4 0 4 
0 0 0 
1 3 2 ;
run;

Hello,

I have 3 numeric variables. I would like to create a new variable which retrieves each time, by observation, the greatest value between my 3 numerical variables.

For example:
V1=3 V2=1 V3=1 then New_V=3
V1=2 V2=3 V3=2 then New_V=3
V1=1 V2=1 V3=2 then New_V=2
V1=0 V2=2 V3=3 then New_V=3
V1=4 V2=0 V3=4 then New_V=4
V1=0 V2=0 V3=0 then New_V=0
V1=1 V2=3 V2=2 then New_V=3

Thank you in advance for your assistance.

 

Gick

1 ACCEPTED SOLUTION
2 REPLIES 2
ballardw
Super User

First item, the semicolon that ends a datalines block must be on its own line.

 

data try_data;
   input V1 V2 V3;
  new_v = max(v1,v2,v3);
datalines;
3 1 1 
2 3 2 
1 1 2 
0 2 3 
4 0 4 
0 0 0 
1 3 2
 ;
run;

There a many functions for statistics of variables in a single record in SAS: N, NMISS, MAX, MIN, MEAN, MEDIAN, IQR, STD and more.

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