Hi guys, I have a dataset that looks like this:
Patient ID | Age1 | Age 2 | Age3 | Age4 | Age5 |
1 | 65 | 60 | 45 | 50 | 24 |
2 | 30 | 66 | 82 | 71 | 58 |
3 | 29 | 45 | 18 | 10 | 31 |
How do I create a 6th column (Age_final) where Age_final is the highest value identified from the 5 columns. Please note that my dataset has hundreds of rows.
An ideal dataset will look like this:
Patient ID | Age1 | Age 2 | Age 3 | Age4 | Age5 | Age_final |
1 | 65 | 60 | 45 | 50 | 24 | 65 |
2 | 30 | 66 | 82 | 71 | 58 | 82 |
3 | 29 | 45 | 18 | 10 | 31 | 45 |
Please try:
Age_final=max(age1,age2,age3,age4,age5)
Use either function max() or largest()
data sample;
infile datalines truncover;
input id age1-age5;
max_age_1=largest(1,of age:);
max_age_2=max(of age:);
datalines;
1 5 4 6 9 2
;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.