How do I find the percentage of people in a group

2019-07-24 23:59发布

DATA test;
INPUT name$ group_no$;
CARDS;
John 1 
Michelle 1
Peter 1 
Kai 2
Peter 2
Liam 2
Claire 2 
Sam 3
Jim 3
run;

How do I find the percentage of people within each group. i.e 33.3% in group 1. 44.4% in group 2 etc....

I tried using the code below but it was not sufficient in answering my question. I believe I may have to use SQL code;

Proc FREQ data = test;
TABLE group_no;
BY group_no;
RUN;

Please let me know how to solve the issue.

标签: sas
2条回答
Evening l夕情丶
2楼-- · 2019-07-25 00:51
Proc FREQ data = test;
   TABLE group_no;
   RUN;

enter image description here

查看更多
冷血范
3楼-- · 2019-07-25 00:59

proc means as shown by data null is the way to go. In SQL you can do as shown below.

 proc sql;
select group_no, 
  count(group_no) *100/(select count(*) from test) as percentage format= 5.2
from test
group by group_no
 ;
查看更多
登录 后发表回答