I have a categorical variable, say SALARY_GROUP, and a group variable, say COUNTRY. I would like to get the relative frequency of SALARY_GROUP within COUNTRY in SAS. Is it possible to get it by proc SUMMARY or proc means?
Asked
Active
Viewed 615 times
0
-
Possible duplicate of [SAS--calculating mean by multiple groups](https://stackoverflow.com/questions/47444022/sas-calculating-mean-by-multiple-groups) – user667489 Mar 26 '18 at 12:42
-
Why not use proc freq? – Dominic Comtois Mar 26 '18 at 17:33
2 Answers
0
Yes, You can calculate the relative frequency of a categorical variable using both Proc Means
and Proc Summary
. For both procs you have to:
-Specify NWAY in the proc statement,
-Specify in the Class statement your categorical fields,
-Specify in the Var statement your response or numeric field.
Example below is for proc means:
Dummy Data:
/*Dummy Data*/
data work.have;
input Country $ Salary_Group $ Value;
datalines;
USA Group1 100
USA Group1 100
GBR Group1 100
GBR Group1 100
USA Group2 20
USA Group2 20
GBR Group2 20
GBR Group1 100
;
run;
Code:
*Calculating Frequncy and saving output to table sg_means*/
proc means data=have n nway ;
class Country Salary_Group;
var Value;
output out=sg_means n=frequency;
run;
Output Table:
Country=GBR Salary_Group=Group1 _TYPE_=3 _FREQ_=3 frequency=3
Country=GBR Salary_Group=Group2 _TYPE_=3 _FREQ_=1 frequency=1
Country=USA Salary_Group=Group1 _TYPE_=3 _FREQ_=2 frequency=2
Country=USA Salary_Group=Group2 _TYPE_=3 _FREQ_=2 frequency=2

momo1644
- 1,769
- 9
- 25
-
-
Can you add an example of the output you want / relative frequency based on my dummy data? I will update my code. – momo1644 Mar 27 '18 at 17:58