Actually, now that I look at it, this isn't a bug at all. Using END REPEAT PRINT to show us what is actually going on, we see this:
if (op1=ans1) indx1=1.
if (indx1>0) score_sum= sum(score_ans1).
if (op2=ans2) indx2=1.
if (indx2>0) score_sum= sum(score_ans2).
if (op3=ans3) indx3=1.
if (indx3>0) score_sum= sum(score_ans3).
if (op4=ans4) indx4=1.
if (indx4>0) score_sum= sum(score_ans4).
if (op5=ans5) indx5=1.
if (indx5>0) score_sum= sum(score_ans5).
if (op6=ans6) indx6=1.
if (indx6>0) score_sum= sum(score_ans6).
if (op7=ans7) indx7=1.
if (indx7>0) score_sum= sum(score_ans7).
if (op8=ans8) indx8=1.
if (indx8>0) score_sum= sum(score_ans8).
if (op9=ans9) indx9=1.
if (indx9>0) score_sum= sum(score_ans9).
if (op10=ans10) indx10=1.
if (indx10>0) score_sum= sum(score_ans10).
execute.
Clearly, that's not going to work, since the SUM function is going over only one variable each invocation.
On the other hand, the other way we both found gives:
if (op1=ans1) indx1=score_ans1.
if (op2=ans2) indx2=score_ans2.
if (op3=ans3) indx3=score_ans3.
if (op4=ans4) indx4=score_ans4.
if (op5=ans5) indx5=score_ans5.
if (op6=ans6) indx6=score_ans6.
if (op7=ans7) indx7=score_ans7.
if (op8=ans8) indx8=score_ans8.
if (op9=ans9) indx9=score_ans9.
if (op10=ans10) indx10=score_ans10.
execute.
compute score_sum=sum(indx1 to indx10).
execute.
** which is going to do exactly what you want; within a case, it's going to go across variables.
------------------------------
Rick Marcantonio
Quality Assurance
IBM
------------------------------
Original Message:
Sent: Sun February 26, 2023 08:39 AM
From: Meni Berger
Subject: DO REPEAT can not sum stand-in variables when using if conditions.
yes. that's the approach I took when I noticed this issue.
but it's just overlooking the issue, ain't it? looks like a DO REPEAT malfunction to me.
------------------------------
Meni Berger
------------------------------
Original Message:
Sent: Wed February 22, 2023 11:19 AM
From: Rick Marcantonio
Subject: DO REPEAT can not sum stand-in variables when using if conditions.
How about this?
DO REPEAT op= op1 to op10
/ans= ans1 to ans10
/score= score_ans1 to score_ans10
/indx= indx1 to indx10.
if (op=ans) indx=score.
END REPEAT.
compute score_sum=sum(indx1 to indx10).
EXECUTE.
------------------------------
Rick Marcantonio
Quality Assurance
IBM
Original Message:
Sent: Wed February 22, 2023 03:41 AM
From: Meni Berger
Subject: DO REPEAT can not sum stand-in variables when using if conditions.
Thanks, Rick.
leave command has no effect.
the sum function returns a value, but it seems he is ignoring the condition and only produces the last value from the score if indx equals 1.
------------------------------
Meni Berger
Original Message:
Sent: Tue February 21, 2023 11:01 AM
From: Rick Marcantonio
Subject: DO REPEAT can not sum stand-in variables when using if conditions.
I haven't tried myself yet, but it occurs to me, did you try inserting the LEAVE command?
if (indx>0) score_sum= sum(score).
LEAVE score_sum.
I'll check myself in a bit, just can't at the moment.
------------------------------
Rick Marcantonio
Quality Assurance
IBM