BenefUserID | BenefPriID | BenefRelToPriID |
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 |
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.
Anytime, glad to help 🙂
Best, Peter.
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;
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
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
Thank you. That helps. My other question is, in what kind of cases we use "proc means mode" ?
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;
Thank you so much. Appreciate your help.
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.