## Observations with Tied maximum values

Solved
Occasional Contributor
Posts: 16

# Observations with Tied maximum values

I have another question to expound on an original topic on finding the variable that contains the minimum value in each row for each observation presented by Rick Wicklin earlier this year in May. I am hoping someone could assist me in modifying my SAS code to flag an observation with tied/duplicate maximum values-because right now I have structured my code to determine the max and give me the variable name of that value. Say the dataset is:

data one;

input ID A B C D E F;

cards;

FID4563   1      3      12      6    15  15

FID568   34    583    294   493   2    4

FID34      34    90      3       0    90   0

;

run;

I still want to obtain the maximum of the variables (a-f) for each ID but want to create an additional variable that acts to flag/differentiate those observations in which the max is tied as for IDs 4563 and 34 so that I know those observations would need to be examined further in a separate dataset. I am interested in doing this because I know those IDs were classified really as two groups instead of one which SAS defaulted to.

data program_results; length maxVar \$32; set program6;

array arr

• A B C D E F;
• maxVar =vname(arr[whichn(max(of arr

• ), of arr
• )]);
• run;

Thank you, Cara

Accepted Solutions
Solution
‎11-08-2012 02:48 PM
PROC Star
Posts: 8,164

## Re: Observations with Tied maximum values

Here is one possible approach:

data one;

input ID \$ A B C D E F;

cards;

FID4563   1      3      12      6    15  15

FID568   34    583    294   493   2    4

FID34      34    90      3       0    90   0

;

run;

data program_results;

length maxVar \$32;

length ties \$1;

set one;

array arr

• A--F;;
•   maxVar =vname(arr[whichn(max(of arr

• ), of arr
• )]);
•   ties=ifc(count(catx(" ",of arr

• ),strip(put(max(of arr
• ),best12.))) gt 1,"*","");
• run;

All Replies
Solution
‎11-08-2012 02:48 PM
PROC Star
Posts: 8,164

## Re: Observations with Tied maximum values

Here is one possible approach:

data one;

input ID \$ A B C D E F;

cards;

FID4563   1      3      12      6    15  15

FID568   34    583    294   493   2    4

FID34      34    90      3       0    90   0

;

run;

data program_results;

length maxVar \$32;

length ties \$1;

set one;

array arr

• A--F;;
•   maxVar =vname(arr[whichn(max(of arr

• ), of arr
• )]);
•   ties=ifc(count(catx(" ",of arr

• ),strip(put(max(of arr
• ),best12.))) gt 1,"*","");
• run;

Occasional Contributor
Posts: 16

## Re: Observations with Tied maximum values

Arthur, you are the best. Thank you so very much! Cara

Posts: 3,167

## Re: Observations with Tied maximum values

Or :

data one;

input ID\$ A B C D E F;

cards;

FID4563 1 3 12 6 15 15

FID568 34 583 294 493 2 4

FID34 34 90 3 0 90 0

;

data have;

set one;

array var a--f;

_max=max(of var(*));

do over var;

_ct+(var=_max);

end;

tie=(_ct>1);

_ct=0;

drop _:;

run;

proc print;run;

Haikuo

🔒 This topic is solved and locked.