DATA Step, Macro, Functions and more

How to find the corresponding max value?

Accepted Solution Solved
Reply
Contributor
Posts: 30
Accepted Solution

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: 17,828

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;

View solution in original post


All Replies
Super User
Posts: 17,828

Re: How to find the corresponding max value?

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

Super User
Posts: 10,500

Re: How to find the corresponding max value?

Some questions about your Tag values:

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: 17,828

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: 30

Re: How to find the corresponding max value?

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

Contributor
Posts: 30

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: 17,828

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: 30

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.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 365 views
  • 0 likes
  • 3 in conversation