标题: 统计学生选择题回答正确的个数 [打印本页] 作者: shiyiming 时间: 2011-4-12 20:11 标题: 统计学生选择题回答正确的个数 代码:
data a;
input id$ q1$ q2$ q3$@@;
cards;
01 a b c 02 a b a
03 b a c 04 a b c
;
run;
data b(drop=i);
num=0;
set a;
array q(3);
array crt(3) $_temporary_('a','b','c');
do i=1 to 3;
if q(i)=crt(i) then num+1;
end;
run;
上面的段代码功能只是完成对单选题的判断,要求把单选题的统计个数,改为对多选题的统计。 有多少办法能够实现它!!
方法不要求唯一,大侠们给的代码可以越多越好,让小生跟更多的人也好多学习学习下啊!!!作者: shiyiming 时间: 2011-4-13 11:08 标题: Re: 统计学生选择题回答正确的个数 多关注下啊!!作者: shiyiming 时间: 2011-4-13 20:42 标题: Re: 统计学生选择题回答正确的个数 假如统计多选的测试数据如下:
01 a bc b
02 ac c c
03 a cb b
04 c b b
测试答案为 a,bc,b
其中的bc与cb 看做是同一答案,类似的也一样作者: shiyiming 时间: 2011-4-18 01:06 标题: Re: 统计学生选择题回答正确的个数 [code:9pmlc5t8]data a;
input id$ q1$ q2$ q3$@@;
cards;
01 a bc b
02 ac c c
03 a cb b
04 c b b
;
run;
data b(drop=i);
num=0;
set a;
array q(3);
array crt(3) $_temporary_('a','bc|cb','b');
do i=1 to 3;
if prxmatch('m/'||crt(i)||'/i',q(i)) then num+1;
end;
run;
[/code:9pmlc5t8]作者: shiyiming 时间: 2011-4-19 21:20 标题: Re: 统计学生选择题回答正确的个数 斤点把这个贴给忘了,多谢byes的回复啊,代码中给的方法非常好,在面对选项答案更复杂的时候,也可应用到,比如学生给的答案中除了顺序可以颠倒外,中间还可能涉及到逗号‘ ,’跟多个空格或者还有大小写等多种情况,下面引用下前边byes的那段很好的代码,首先在这里先赞一个,呵呵!!
代码:
[code:3pzr6r9p]
data a;
infile cards dsd;
input id$ q1$ q2$ q3$@@;
cards;
01, a ,"b, c", b
02,"a c", c, c
03, A, "c , b", b
04, C, B, B,
;
run;
data b(drop=i);
num=0;
set a;
array q(3);
array crt(3) $_temporary_('(a|A)','(b|B) *,? *(c|C)|(c|C) *,? *(B|b)','(B|b)');
do i=1 to 3;
if prxmatch('m/'||crt(i)||'/i',q(i)) then num+1;
end;
run;
[/code:3pzr6r9p]
不过改动后 id 为 03 的 q2 好像没有统计出来,也还没找到啥原因造成滴!
最后随便问下那个匹配函数中的m代表的是什么啊?小弟基础功还不扎实,没看明白,也查不到资料,哎!!作者: shiyiming 时间: 2011-4-20 01:02 标题: Re: 统计学生选择题回答正确的个数 [code:21ihk3j3]
data b(drop=i j);
num=0;
set a;
array q(3);
array crt(3) $_temporary_('a','Bc','B');
length c $8;/*存储答案(剔除非字母)*/
array t(4) $1 _temporary_ ;/*假设多选的结果最多是4个*/
do i=1 to 3;
c=compress(q(i),,'ak');
do j=1 to 4;
if j<=length(crt(i)) then t(j)=substr(crt(i),j,1);
else t(j)=t(j-1);
end;
if prxmatch('m/'||t(1)||'/i',c)
and prxmatch('m/'||t(2)||'/i',c)
and prxmatch('m/'||t(3)||'/i',c)
and prxmatch('m/'||t(4)||'/i',c)
and not prxmatch('m/[^'||crt(i)||']/i',c)
then num+1;
end;
run;
[/code:21ihk3j3]作者: shiyiming 时间: 2011-4-21 08:50 标题: Re: 统计学生选择题回答正确的个数 [quote="byes":p50sc2i3][code:p50sc2i3]
data b(drop=i j);
num=0;
set a;
array q(3);
array crt(3) $_temporary_('a','Bc','B');
length c $8;/*存储答案(剔除非字母)*/
array t(4) $1 _temporary_ ;/*假设多选的结果最多是4个*/
do i=1 to 3;
c=compress(q(i),,'ak');
do j=1 to 4;
if j<=length(crt(i)) then t(j)=substr(crt(i),j,1);
else t(j)=t(j-1);
end;
if prxmatch('m/'||t(1)||'/i',c)
and prxmatch('m/'||t(2)||'/i',c)
and prxmatch('m/'||t(3)||'/i',c)
and prxmatch('m/'||t(4)||'/i',c)
and not prxmatch('m/[^'||crt(i)||']/i',c)
then num+1;
end;
run;
[/code:p50sc2i3][/quote:p50sc2i3]
谢谢byes了,还是不清楚 prxmatch中的那个m是啥含义,有没有谁可以提供点相关资料的啊!作者: shiyiming 时间: 2011-4-23 17:41 标题: Re: 统计学生选择题回答正确的个数 有谁还能帮忙找一下前面那段程序统计出错的原因在哪里呀?我都试过好几遍了,id 为 03 的 q2 列始终没统计出来,想知道!!
代码重新粘贴一下:
[code:1z7lv6po]
data a;
infile cards dsd;
input id$ q1$ q2$ q3$@@;
cards;
01, a ,"b, c", b
02,"a c", c, c
03, A, "c , b", b
04, C, B, B,
;
run;
data b(drop=i);
num=0;
set a;
array q(3);
array crt(3) $_temporary_('(a|A)','(b|B) *,? *(c|C)|(c|C) *,? *(B|b)','(B|b)');
do i=1 to 3;
if prxmatch('m/'||crt(i)||'/i',q(i)) then num+1;
end;
run;
[/code:1z7lv6po]作者: shiyiming 时间: 2011-4-23 21:51 标题: Re: 统计学生选择题回答正确的个数 [quote="天性爱好者":13qd3ko5]有谁还能帮忙找一下前面那段程序统计出错的原因在哪里呀?我都试过好几遍了,id 为 03 的 q2 列始终没统计出来,想知道!!
代码重新粘贴一下:
[code:13qd3ko5]
data a;
infile cards dsd;
input id$ q1$ q2$ q3$@@;
cards;
01, a ,"b, c", b
02,"a c", c, c
03, A, "c , b", b
04, C, B, B,
;
run;
data b(drop=i);
num=0;
set a;
array q(3);
array crt(3) $_temporary_('(a|A)','(b|B) *,? *(c|C)|(c|C) *,? *(B|b)','(B|b)');
do i=1 to 3;
if prxmatch('m/'||crt(i)||'/i',q(i)) then num+1;
end;
run;
data b(drop=i);
num=0;
set a;
array q(3);
array crt(3) $_temporary_('(a|A)','(c|C)()*,?()*(B|b)|(b|B)()*,?()*(c|C)','(B|b)');
do i=1 to 3;
if prxmatch('m/'||crt(i)||'/i',q(i)) then num+1;
end;
run;
[/code:1qk01gml]
前面的这个[color=#FF0000:1qk01gml]([/color:1qk01gml]id 为 01 的 q2列[color=#FF0000:1qk01gml]"b, c"[/color:1qk01gml]能够统计出来,而 id 为 03 的 q2列[color=#FF0000:1qk01gml]"c , b"[/color:1qk01gml]就不会统计出来[color=#FF0000:1qk01gml] )[/color:1qk01gml]问题是到解决了,不过新问题又产生了,经过测试发现,[color=#FF0000:1qk01gml]id 号 为 02 的 q2 列不正确,却把它统计成正确的了[/color:1qk01gml],这下更搞不清源头了!! 好心的大哥大姐们就把代码拿去测试测试,帮忙找找缘由吧!!谢谢啦!作者: shiyiming 时间: 2011-5-22 12:48 标题: Re: 统计学生选择题回答正确的个数 [code:1x76ckqi]
data a;
infile cards dsd;
input id$ q1$ q2$ q3$@@;
cards;
01, a ,"b , c", b
02,"a c", c, c
03, A, "c , b", b
04, C, B, B,
;
run;
data b(drop=i);
num=0;
set a;
array q(3);
array crt(3) $_temporary_('a','bc|cb','b');
do i=1 to 3;
q(i)=PRXCHANGE('s/,/ /',-1,q(i));
q(i)=PRXCHANGE('s/\s//',-1,q(i));
if prxmatch('/'||crt(i)||'/i',q(i)) then num+1;
end;
run;
[/code:1x76ckqi]作者: shiyiming 时间: 2011-5-22 21:53 标题: Re: 统计学生选择题回答正确的个数 不错!必须滴赞一下楼上的... 呵呵 <!-- s:D --><img src="{SMILIES_PATH}/icon_biggrin.gif" alt=":D" title="Very Happy" /><!-- s:D -->