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!
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;
PROC FREQ with the ORDER=FREQ option should get you started.
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.
Yes. Thank you. I want to find the most frequent occurence_tag by types.
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.
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;
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!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.