Set Household number Restriction

Other discussions about CSPro
Posts: 128
Joined: November 18th, 2014, 1:55 am

Set Household number Restriction

Postby MrTaco » June 7th, 2017, 5:45 am

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");
but it's not working.

Posts: 1651
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Set Household number Restriction

Postby josh » June 7th, 2017, 5:55 am

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.

Return to “Other”