I have put this in a new thread because as David pointed out this is a
new topic. Netiquette is to start a new thread.
The file "final" has the info.
see below sig block.
Alternative approaches might be to use FREQUENCIES and MEANS and then
OMS or to use CTABLES.
Art Kendall
Social Research Consultants
*VARTOCASES was lossing files so they were copied to temp1 and temp2.
*.
*this is still a KLUDGE.
*.
*It has not yet been re-drafted for efficiency.
*It has not yet been re-drafted for readability.
* The macros and test data were from a post by David Marso.
*.
DEFINE DUMCODES (QX !TOKENS(1)/VR !TOKENS(1)/MAX !TOKENS(1)/ ANS
!TOKENS(1)/ KEY !TOKENS(1) )
NUMERIC !CONCAT(SUM_,!QX)(F8.0).
!DO !I = 1 !TO !MAX
!LET !VLIST=""
!DO !A=1 !TO !LENGTH(!ANS)
!LET !VNAME=!CONCAT(!VR,!I,"_",!SUBSTR(!ANS,!A,1) ,"_" )
!IF (!SUBSTR(!KEY,!I,1)=!SUBSTR(!ANS,!A,1)) !THEN !LET !VN="C"
!LET !CINDEX=!A !ELSE !LET !VN="W" !IFEND
!LET !VNAME=!CONCAT(!VNAME,!VN) !LET !VLIST=!CONCAT(!VLIST,!VNAME," ")
!DOEND
!LET !FIRST=!HEAD(!VLIST) !LET !LAST=!VNAME
+ NUMERIC !VLIST (F1).
+ RECODE !VLIST (ELSE=0).
+ VECTOR !CONCAT(!VR,!I)=!FIRST TO !LAST .
+ COMPUTE !CONCAT(!VR,!I)(INDEX(!QUOTE(!ANS),!CONCAT(!QX,!I), 1))=1.
+ COMPUTE !CONCAT(SUM_,!QX)
=SUM(!CONCAT(SUM_,!QX),!CONCAT(!VR,!I)(!CINDEX)).
!DOEND
!ENDDEFINE.
DATA LIST / Q1 TO Q20 (20A1).
BEGIN DATA
ABBACDCNCBDCABBANCBA
DCACBBCADNBCACBCABAC
ABCBDCABBCADNACBCABA
CBDCABBANCBAABBACDCN
BCACBCABACDCACBBCADN
BCADNACBCABAABCBDCAB
ABCBACBCADACBCADBBCA
AAAAAAAAAAAAAAAAAAAA
BBBBBBBBBBBBBBBBBBBB
ABCBACBCADACBCADBBCA
END DATA.
dataset name rawfile.
EXECUTE.
dataset copy temp1.
dataset activate temp1.
SET MPRINT ON.
DUMCODES QX Q VR X MAX 20 ANS ABCDN KEY ABCBACBCADACBCADBBCA .
* new part.
dataset name widefile.
dataset copy temp2.
dataset activate temp2.
VARSTOCASES
/ID=id
/MAKE dummy FROM X1_A_C to X20_N_W
/INDEX=Index1(dummy)
/KEEP=SUM_Q
/NULL=KEEP.
DATASET NAME longfile.
numeric question (n2).
string answer (a5)correctwrong(a1).
do if substr(index1,3,1) eq '_'.
compute question = number(substr (index1,2,1),n2).
compute answer = substr(index1,4,1).
compute correctwrong =substr(index1,6,1).
ELSE.
compute question = number(substr (index1,2,2),n2).
compute answer = substr(index1,5,1).
compute correctwrong =substr(index1,7,1) .
end if.
string star(a1).
recode correctwrong ('W'= ' ')('C'='*')into star.
COMPUTE SUM2_Q = SUM_q* DUMMY.
MISSING VALUES SUM2_Q (0).
dataset declare HITS.
aggregate outfile = HITS
/break = question answer
/star = first(star)
/pct_hits = pin(dummy,1,1)
/hit_score = mean(sum2_q).
dataset activate HITS.
formats pct_hits (pct6.1) hit_score(f7.3) .
dataset activate longfile.
dataset declare totals.
temporary.
compute answer='total'.
aggregate outfile = totals
/break = question
/answer = first(answer)
/pct_hits = pin(dummy,0,1)
/hit_score = mean(sum2_q).
dataset activate totals.
formats pct_hits (pct6.1) hit_score(f7.3) .
dataset declare final.
add files file=hits /file= totals.
dataset name final.
sort cases by question answer.