BookmarkSubscribeRSS Feed
Mick_lb
Calcite | Level 5

Hello everyone,

 

I have a table containing one satisfaction score on three criteria for several individuals.

My table is presented as follows :

Note_A / Note_B / Note_C

10            12          14

16              14          8

15            16          12

......

 

I want to create two new columns "Max_note_1" and "Max_note_2" that take the two highest scores for each person.

 

How can I do this ?

 

Thank you in advance for your help !

 

Best regards, 

2 REPLIES 2
ed_sas_member
Meteorite | Level 14

Hi @Mick_lb 

 

You can use the LARGEST() function that returns the xth largest non-missing value.

 

best,

data have;
	input Note_A Note_B Note_C;
	datalines;
10 12 14
16 14 8
15 16 12
;
run;

data want;
	set have;
	Max_note_1 = largest(1, Note_A, Note_B, Note_C);
	Max_note_2 = largest(2, Note_A, Note_B, Note_C);
run;
PeterClemmensen
Tourmaline | Level 20

I assume that each observation is one person?

 

In that case, use the Largest function

 

data have;
input Note_A Note_B Note_C;
datalines;
10 12 14
16 14 8
15 16 12
;

data want;
    set have;
    Max_note_1 = max(of Note:);
    Max_note_2 = largest(2, of Note:);
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 2 replies
  • 576 views
  • 3 likes
  • 3 in conversation