Page 1 of 1

Set Household number Restriction

Posted: June 7th, 2017, 5:45 am
by MrTaco
Hi guys

I want to restrict HH_Number not be entered twice in 2 different questionnaires.

Code: Select all

if $ = HH_Number then
	errmsg("You must select another number");
	reenter;
endif;
but it's not working.

Re: Set Household number Restriction

Posted: June 7th, 2017, 5:55 am
by josh
If you are trying to compare the current value of HH_Number to one that was previously entered that won't work because only case is loaded at a time.

If HH_Number is an id-item then you could use the keylist() function to get the list of previous cases, extract the HH_Number from each key and compare it to the HH_Number just entered.

If HH_Number is not an id-item then you would need to write the HH_Number to an external data file each time it is entered using writecase and then use loadcase to check to see if each new one is a duplicate.

You could also consider setting HH_Number to be auto-increment in which case it will automatically be increased by one for each household. This way it will be unique.

Finally if HH_Number is your ONLY id variable then you don't need to anything. CSPro will give an error if it is not unique.