Solved
Contributor
Posts: 32

# How to find the corresponding max value?

Hello, everyone

I have a dataset showing below:

data have;
input
Type \$ date\$ tag\$;
datalines;
A date1 T1
A date2 T2
A date3 T1
A date4 T3
A date5 T1
A date6 T2
B date1 T3
B date2 T2
B date3 T3
B date4 T3
B date5 T1
;

I need the result:

Type Max_tag  Max_N  percent  Total_tag
A         T1          3            50%        6
B         T3          3            60%        5

Any suggestions will be very appreciated!

Accepted Solutions
Solution
‎03-14-2016 05:37 PM
Super User
Posts: 23,771

## Re: How to find the corresponding max value?

100K observations is trivial in SAS.

``````proc freq data=have order=freq;
table type*tag/out=want outpct;
run;

proc sort data=want;
by type descending count;
run;

data want2;
set want;
by type;
if first.type;
run;

proc print data=want2;run;``````

All Replies
Super User
Posts: 23,771

## Re: How to find the corresponding max value?

PROC FREQ with the ORDER=FREQ option should get you started.

Super User
Posts: 13,583

## Re: How to find the corresponding max value?

Are the only values T1, T2, T3?

If you have values like T11 is that supposed to be larger than T3?

Definition of "maximum" for character variables can sometimes be a bit tricky.

Super User
Posts: 23,771

## Re: How to find the corresponding max value?

I don't think @Yurie means 'max', I think they're referring to the most frequent occurence.

Contributor
Posts: 32

## Re: How to find the corresponding max value?

Yes. Thank you. I want to find the most frequent occurence_tag by types.

Contributor
Posts: 32

## Re: How to find the corresponding max value?

Thank you for your response. I want to find the mode and the value of the mode (most frequent occured tags by type. For example, If T2 occured 20 times and it's the most occurence. I need the number "20" and the tag name "T2"). My database is big with more than 100,000 observations.

Solution
‎03-14-2016 05:37 PM
Super User
Posts: 23,771

## Re: How to find the corresponding max value?

100K observations is trivial in SAS.

``````proc freq data=have order=freq;
table type*tag/out=want outpct;
run;

proc sort data=want;
by type descending count;
run;

data want2;
set want;
by type;
if first.type;
run;

proc print data=want2;run;``````
Contributor
Posts: 32

## Re: How to find the corresponding max value?

Wow, you are an expert! Thank you so, so much for your big help! This is what I need! I would like to send you a "thank you" card if I am able to!

🔒 This topic is solved and locked.