BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Yurie
Fluorite | Level 6

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

7 REPLIES 7
Reeza
Super User

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

ballardw
Super User

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.

Reeza
Super User

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

 

 

Yurie
Fluorite | Level 6

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

Yurie
Fluorite | Level 6

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. 

Reeza
Super User

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;
Yurie
Fluorite | Level 6

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!

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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