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

Accepted Solutions
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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 1065 views
  • 0 likes
  • 3 in conversation