SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 538|回复: 2
打印 上一主题 下一主题

如何通过程序直接计算频数,并进行卡方检验

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
楼主
 楼主| 发表于 2011-5-25 23:51:59 | 只看该作者

如何通过程序直接计算频数,并进行卡方检验

如题,我想了一种解决办法但是觉得有点复杂了,求更简单的方法。
data tmp;
input y x@@;
cards;
1 0 1 1 0 0 1 0
1 0 0 1 0 0 1 0
1 0 1 0 1 0 1 0
1 1 1 0 0 0 0 0
1 0 1 0 0 0 0 0
;
data tm;
set tmp end=last;
retain n1 0;
retain n2 0;
retain n3 0;
retain n4 0;
if x=0 and y=0 then n1+1;
if x=0 and y=1 then n2+1;
if x=1 and y=0 then n3+1;
if x=1 and y=1 then n4+1;
if last then output;
run;
data tm2(keep=a b x);
set tm;
a=0 ;
b=0;
x=n1;
output;
  a=0 ;
b=1;
x=n2;
output;
  a=1 ;
b=0;
x=n3;
output;
  a=1 ;
b=1;
x=n4;
output;
run;
proc freq;
        weight x;
       tables  a*b/chisq ;*measures;
run;
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
沙发
 楼主| 发表于 2011-5-26 07:32:40 | 只看该作者

Re: 如何通过程序直接计算频数,并进行卡方检验

Firstly, seemingly we can use FREQ directly;
When to compute frequency at first in our own code, we may consider SQL more convenient; the ways are like the followings.
I hope it is helpful.
JingJu

[code:36cmh6gr]proc freq data =tmp;
tables x*y/chisq ;
run; [/code:36cmh6gr]

[code:36cmh6gr]proc sql;
        create table tmp1 as
                select count(*) as w, x, y from tmp group by x, y;
quit;
proc freq data =tmp1;
        weight w;
        tables x*y/chisq;
run;[/code:36cmh6gr]
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
板凳
 楼主| 发表于 2011-5-26 14:15:48 | 只看该作者

Re: 如何通过程序直接计算频数,并进行卡方检验

Thank you very much!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2025-7-4 05:51 , Processed in 0.098172 second(s), 19 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表