Stop entering same value for variable more than two time

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

Stop entering same value for variable more than two time

Post by gbos »

Dear Josh,

In my household roster, I wanted to make sure that each household head can have only two parent. So, I used a numeric variable in my
PROC GLOBAL: numberParents = 0; then

// Using a numeric variable (defined in PROC GLOBAL), make sure that each head of household can have only two parents.

if s1q6 = 10 then // parent

if numberParents = 3 then
errmsg("You cannot add a third parent to the household");
reenter;

else
inc(numberParents);

endif;

endif;


Sometimes, I get the error message during data entry even if 10 was entered for s1q6 once. I wanted a situation that the error pops up when you enter 10 for s1q6 more than twice for a given record for the household roster. Is there any other walk around this so that when attempt to enter 10 for s1q6 three time for any given record for the roster the error pops up. Attached is a copy of my survey for your attention.
noel
Posts: 25
Joined: June 16th, 2012, 7:32 pm
Location: Libreville, Gabon

Re: Stop entering same value for variable more than two time

Post by noel »

Since you want to be sure that in your household roster, the head of household cannot have more than two parents, it is better to count the number of person where S1Q6 = 10 each time you enter a new parent. You may replace try to replace your logic by the following one:

if $ = 10 then // parent
numberParents = count(SECT1000 where $ = 10);
if numberParents > 2 then
errmsg("You cannot add a third parent to the household");
reenter;
endif;
endif;
gbos
Posts: 51
Joined: June 18th, 2015, 7:49 pm

Re: Stop entering same value for variable more than two time

Post by gbos »

Thanks Noel, that is exactly the solution I am looking for. That logic worked perfectly fine. Once again thanks. :D ;)
Post Reply