Skipping a roster and pre-filling some of the variables

Discussions about CSEntry
Post Reply
gbos
Posts: 51
Joined: June 18th, 2015, 7:49 pm

Skipping a roster and pre-filling some of the variables

Post by gbos »

I was trying to automate some skips in my application with little success and the skip conditions are here explained. I have a household roster and rosters sections 4c, section4d, section 4e and section 4f. I want the following happen skips :

1. if in my section 4c, if s4cq4 = 0 and s4cq5 = 0 then
check if age in years , s1q4a > 5 for any/all id NUMBER(s) IN Section1 then
fill s4dq1 with the Corresponding idnums from Hhousehold roster in section1 and s4dq2 with X
repeat the same for s4eq1 and s4eq2 in sections 4e and skip to sections 4f.

2. If in Section 4c , s4cq4 <> 0 and s4cq5 <> 0 then
if ID number on section 4c, s4cq1 is duplicated then
skip to section4d

Attached is a copy of my survey.
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Skipping a roster and pre-filling some of the variables

Post by josh »

In the preproc of the section 4d form or roster (you could also use postproc of section 4c) I would use a loop to go through each of the rows of the 4c roster i.e. loop from 1 to totocc(SECT4C000). In the loop you check if s4cq4 = 0 and s4cq5 = 0 and if s1q4a > 5 and if it is you fill in the next id in s4qd1. You would need a variable to keep track of the next available row in the sect4d roster. The code would look something like:

Code: Select all

numeric nextAvailable = 1;
numeric i;
do i = 1 to totocc(SECT4C000)
  if  s4cq4(i) = 0 and s4cq5(i) = 0 and s1q4a(i) > 5 then
    S4DQ1(nextAvailable) = S1Q1_IDNO(i);
    S4DQ2(nextAvailable) = X;
    nextAvailable = nextAvailable + 1;
  endif;
enddo;
gbos
Posts: 51
Joined: June 18th, 2015, 7:49 pm

Re: Skipping a roster and pre-filling some of the variables

Post by gbos »

Josh thanks for the prompt reply. I tried testing the logic in the preproc of my sect4d. However, i noticed the following:

the logic wouldn't compile, so I replaced your logic with the following which compiled successfully.

numeric nextAvailable = 1;
numeric m;


do varying m = 1 until m > totocc(SECT4C000)
if s4cq4(m) = 0 and s4cq5(m) = 0 and s1q4a(m) > 5 then
S4DQ1(nextAvailable) = S1Q1_IDNO(m);
S4DQ2(nextAvailable) = "X";
nextAvailable = nextAvailable + 1;
endif;
end do;
For the skip i had the following in the same preproc directly below the above:

numeric xSkip_Sect4d = count(SECT4c000 where S4cQ4 > 0 and s4cq5 > 0);
if !xSkip_Sect4d then
endgroup;
endif;


Even when it compiled successfully, it will only skip without filling the s4dq1 and s4dq2; even when I populated sect1 with ages more than 5 yrs.
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Skipping a roster and pre-filling some of the variables

Post by josh »

Sorry about the compile errors in the logic. I didn't get a chance to test it. Glad you were able to correct them.

Using endgroup will cause the roster to end early. You don't really want the roster to be skipped. Instead you should advance through them using the advance statement. Advance is like skip in that it moves you forward in the questionnaire but unlike advance it simulates going through each field and hitting enter, so values are saved and procs are run. So instead of using endgroup use "advance to SECT4E_FORM" to move to the form that follows section 4D.

Note that with advance, since it simulates hitting enter on every field you may need to add some skips/logic to the fields that you are advancing through so that any edit checks that you have in those field don't cause problems as you advance through.
gbos
Posts: 51
Joined: June 18th, 2015, 7:49 pm

Re: Skipping a roster and pre-filling some of the variables

Post by gbos »

Dear Josh,
Am happy to report that the program is now working fine, having tested few cases. However, one thing remained unsolved, that is, when the program is filling the IDs and X's it doesn't march exactly the IDs. For instance, On the Household Roster if IDnum 1,2,3,4 are eligible should be filled exactly and sequentially on say sect4a. So that if id 2,3 are not eligible they must be skipped at the time they are being filled on the required corresponding form, section 4a. For instance, if you kindly have a look at section 4a, q2 of my survey, you will see that it is indicated "mark X if age on section 1, s1q4a is greater than or equal to 5. if on section1 id numbers/line numbers, 1,2 ,3 are eligible and 4,5 are not and say 6,7, 8 etc are eligible, i want the s4aq1 and s4aq2 be filled with id/line numbering 1,2,3 and X's, accordingly. Since ids/line numbers 4,5 are not eligible, they be skipped and id/line numbering continues at 6,7,8 etc on section4a. Here is what I could think of, which I put in the preproc of sect4a

numeric nextAvailable = 1;
numeric m;

do varying m = 1 until m > totocc(SECT1000)

if s1q4a(m) >= 5 then
S4aQ1(nextAvailable) = S1Q1_IDNO(m);
S4aQ2(nextAvailable) = "X";
nextAvailable = nextAvailable + 1;
endif;
enddo;

I now need to improve on this with some function, like the seek function which will seek and march the idnum/line number on section 1, the household roster to that of section4a. My problem is I don't know how or which function to use. Any help will be welcomed.
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Skipping a roster and pre-filling some of the variables

Post by josh »

Are you saying that you want a one to one correspondance between lines on sect 4a and section 1? In other words if there are ineligible household members in section 4a you still want blank lines in that section for them?

If that is the case then you don't need the loop at the start of the form/roster. Instead you can just handle it in the preproc of the fields. So to set the id number in sect 4 to the id number from the corresponding row in section 1 you would do:

PROC S4AQ1
preproc
// Copy id number from section 1
S4AQ1 = S1Q1_IDNO(curocc());

Then to set the X if age is 5 or over:

PROC S4AQ2
preproc
if S1Q4A(curocc()) >= 5 then
S4aQ2 = "X";
endif;

The only tricky part is that you need to curocc() to get the current row number of the section 4 roster to use as a subscript in the in the section 1 roster. You can also use noinput or make those fields protected if you want to since they are filled in automatically.
gbos
Posts: 51
Joined: June 18th, 2015, 7:49 pm

Re: Skipping a roster and pre-filling some of the variables

Post by gbos »

Thanks Josh for the reply. Absolutely, I want to set one to one correspondence between line numbers of section 1 to those of section4a. Therefore, if s1q4a >= 5 then automatically fill s4aq1 and s4aq2 with idnums and X's respectively from Section1 when section4a is in focus. I want to achieve this one time if section 4a is in focus. The logic you presented as a solution fills only by visiting the s4aq1 and s4aq2 when in actual fact i want it to happen automatically one time anytime section 4a is in focus for all the cases in section 1.

Therefore the logic above did not automatically insert the IDs and X's when tested. Could you have a look once more? I will grateful. This logic earlier on presented which I had in preproc of sect4a as follows:-

numeric nextAvailable = 1;
numeric m;

do varying m = 1 until m > totocc(SECT1000)

if s1q4a(m) >= 5 then
S4aQ1(nextAvailable) = S1Q1_IDNO(m);
S4aQ2(nextAvailable) = "X";
nextAvailable = nextAvailable + 1;
endif;
enddo;

Is doing exactly what I wanted to achieve, except that there is no one to one correspondence between line numbers of section 1 and section 4a which is what I wanted to achieve. I will be grateful if you can have a look again. Thanks for all the support Josh.
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Skipping a roster and pre-filling some of the variables

Post by josh »

In that case, just the loop index instead of the nextAvailable variable in the loop:

Code: Select all

numeric m;

do varying m = 1 until m > totocc(SECT1000) 
    S4aQ1(m) = S1Q1_IDNO(m);
    if s1q4a(m) >= 5 then
        S4aQ2(m) = "X";
    endif;
enddo;
gbos
Posts: 51
Joined: June 18th, 2015, 7:49 pm

Re: Skipping a roster and pre-filling some of the variables

Post by gbos »

Dear Josh,
Once gain thanks and thanks a million times. Even that isn't enough for me. This is exactly what I was trying to accomplish. The logic you presented works fine!!! :D
Post Reply