Set Household number Restriction

Other discussions about CSPro
Forum rules
New release: CSPro 8.0
Post Reply
MrTaco
Posts: 128
Joined: November 18th, 2014, 1:55 am

Set Household number Restriction

Post 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.
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Set Household number Restriction

Post 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.
Post Reply