DATA Step, Macro, Functions and more

Need help with SAS proc Mode

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

Need help with SAS proc Mode

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.


Accepted Solutions
Solution
‎06-15-2017 04:54 AM
PROC Star
Posts: 734

Re: Need help with SAS proc Mode

[ Edited ]

Anytime, glad to help Smiley Happy

 

Best, Peter.

View solution in original post


All Replies
PROC Star
Posts: 734

Re: Need help with SAS proc Mode

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;
Occasional Contributor
Posts: 8

Re: Need help with SAS proc Mode

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

PROC Star
Posts: 734

Re: Need help with SAS proc Mode

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

Occasional Contributor
Posts: 8

Re: Need help with SAS proc Mode

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

PROC Star
Posts: 734

Re: Need help with SAS proc 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;
Occasional Contributor
Posts: 8

Re: Need help with SAS proc Mode

Thank you so much. Appreciate your help.

Solution
‎06-15-2017 04:54 AM
PROC Star
Posts: 734

Re: Need help with SAS proc Mode

[ Edited ]

Anytime, glad to help Smiley Happy

 

Best, Peter.

☑ This topic is solved.

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

Discussion stats
  • 7 replies
  • 136 views
  • 1 like
  • 2 in conversation