I am currently working on a roster where values from earlier rows (e.g., Q201 and Q202A) need to be copied into later rows automatically when certain conditions are met (based on the number entered in Q202A).
In my logic, I used the skip to statement to move directly to the next question after copying values. However, I have observed that using skip causes the copied data to be lost due to how skip logic works.
Here is the relevant part of my code:
if not special(Q201_help(m)) then
Q201_help = Q201_help(m);
Q201 = Q201_help(m);
Q202A = Q202A(m);
skip to Q201A;
exit;
endif;
My Questions
Is there a safe alternative to skip that allows auto-filling values without losing copied data?
Is there a recommended approach for preloading values from earlier rows while still keeping the questionnaire flow intact?
Context
Q201_help is numeric and uses a dynamic value set from the household roster (HHROSTER).
If the enumerator selects option 1 in Q201_help and enters 3 in Q202A, then the same data should be automatically copied into the next two rows.
After that, the enumerator should be able to select another option for Q201_help, and the previous selection should be automatically removed from the available value set.
The logic for building the dynamic value set and ending the roster when all members are selected is included below for reference.
Code: Select all
do m = 1 while m < curocc_var
if Q202A(m) > 1 then
// Limit duplication range to 3 rows max
numeric limit;
limit = Q202A(m);
if limit > 3 then
limit = 3;
endif;
if curocc_var <= m + limit - 1 then
if not special(Q201_help(m)) then
Q201_help = Q201_help(m);
Q201 = Q201_help(m);
Q202A = Q202A(m);
skip to Q201A; // problem line: data disappears
exit;
endif;
endif;
endif;
enddo;
// Build dynamic value set
ValueSet respondent_valueset;
do i = 1 while i <= count(HHROSTER)
if Q139(i) = 1 then // check eligibility
numeric already_selected;
already_selected = 0;
do j = 1 while j < curocc(SEC_2000) // check earlier rows
if Q201_help(j) = LNO(i) then
already_selected = 1;
endif;
enddo;
if already_selected = 0 then
respondent_valueset.add(Q130(i), LNO(i));
endif;
endif;
enddo;
respondent_valueset.add("End Roster", 99);
setvalueset(Q201, respondent_valueset);
if respondent_valueset.length() = 0 then
endlevel; // auto end roster when all members selected
else
setvalueset(Q201_help, respondent_valueset);
endif;
setcapturetype(Q201_help, 1);
Best regards,
BK Singh