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
;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.