* ======================================================================= * File: do_repeat_example.SPS . * Date: 17-Feb-2004 . * Author: Bruce Weaver, weaverb@mcmaster.ca . * Notes: Nice example of a do-repeat loop . * ======================================================================= . * On 17-Feb-2004, Vassilis wrote in newsgroup comp.soft-sys.stat.spss: *> Hi all *> I have a fairly large table (37000 candidates by 75 questions ranging from a *> to f). How can I make a new table showing the correct/wrong answers in the *> form 1,0? *> Thanx *> Vassilis * Mike Lacy posted a very elegant solution, which is demonstrated below, * but using a smaller data set with only 5 questions, and 5 cases. data list list / q1 to q5 (5a1). begin data. a b c d e e c b e a a c c b e b b c d e a e c c a end data. string key (a5). compute key = 'abcda' . /* KEY has the right answers for the 5 questions . numeric right1 to right5 (f1.0). do repeat quest = q1 to q5 / right = right1 to right5 / i = 1 to 5 . - compute right = (quest = substr(key,i,1)). end repeat . compute numright = sum(right1 to right5). format numright(f2.0). exe. list. * ======================================================================= .