BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Sam1010
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
AKHILA
Obsidian | Level 7

Please try:

 

Age_final=max(age1,age2,age3,age4,age5)

 

 

View solution in original post

4 REPLIES 4
AKHILA
Obsidian | Level 7

Please try:

 

Age_final=max(age1,age2,age3,age4,age5)

 

 

Sam1010
Fluorite | Level 6
Great. This works. Thank you.
Patrick
Opal | Level 21

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
;