简体   繁体   中英

sas relative frequencies by group

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?

也许探索proc制表和一个计数器变量?

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 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM