BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
vanaml
Calcite | Level 5
BenefUserIDBenefPriIDBenefRelToPriID
702PID-176Brother
2301PID-1070Husband
1398PID-1089Others
2143PID-1341Wife
2484PID-1441Daughter
2663PID-1474Child
976PID-1115Sister
1942PID-791Mother-in-law
300PID-302Sister
2795PID-872First Child
2532PID-914Sister
374PID-1418Self
918PID-1043Wife
1096PID-878Sister
2672PID-865Wife
1263PID-125Husband
1965PID-1399Second Child
2849PID-184Others

 

The above is my sample dataset and I would like to find out the most common BenefRelToPriID. I believe I need to use Mode option. I am new to SAS programming and I am lost in the syntax. Can someone please help me with the syntax?

 

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Anytime, glad to help 🙂

 

Best, Peter.

View solution in original post

7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20

PROC FREQ will give you the answer

 

data have;
input BenefUserID$ BenefPriID$ BenefRelToPriID$;
datalines; 
702 PID-176 Brother 
2301 PID-1070 Husband 
1398 PID-1089 Others 
2143 PID-1341 Wife 
2484 PID-1441 Daughter 
2663 PID-1474 Child 
976 PID-1115 Sister 
1942 PID-791 Mother-in-law 
300 PID-302 Sister 
2795 PID-872 First Child 
2532 PID-914 Sister 
374 PID-1418 Self 
918 PID-1043 Wife 
1096 PID-878 Sister 
2672 PID-865 Wife 
1263 PID-125 Husband 
1965 PID-1399 Second Child 
2849 PID-184 Others 
;

proc freq data = have order = freq;
	tables BenefRelToPriID / nocum;
run;
vanaml
Calcite | Level 5

Thank you very much. I am now starting to learn SAS and have been exploring multiple options. Can this be done using Mode too? Or in what kind of cases Mode is used? Can you please clarify?

 

Thank you

PeterClemmensen
Tourmaline | Level 20

Not sure what you mean, The mode is the value that appears most often in a set of data, so the mode of the variabel of interest will be the first in the output from PROC FREQ since we order the output

vanaml
Calcite | Level 5

Thank you. That helps. My other question is, in what kind of cases we use "proc means mode" ?

PeterClemmensen
Tourmaline | Level 20

When the variable of interest is numeric like in this small example

 

data testdata;
input ID$ value;
datalines;
1 20
2 30
3 20
4 50
;

proc means data = testdata mode;
	var value;
run;
vanaml
Calcite | Level 5

Thank you so much. Appreciate your help.

PeterClemmensen
Tourmaline | Level 20

Anytime, glad to help 🙂

 

Best, Peter.

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
  • 905 views
  • 1 like
  • 2 in conversation