Page 1 of 1

Function to check duplicate values in multiple response vari

Posted: February 9th, 2013, 2:35 pm
by Bharadwaj
Hi Gregory

I am having many multiple response questions i am using following syntax to check the multiple responses in multiple occurrence field.

i = 0;
do while i < 99
if count ($ where $ in i) > 1 then
errmsg("Duplicate value");
reenter;
endif;
i = i + 1;
enddo;

Instead of this if you can give me any function which i can use easily.

Thanks

Bharadwaj

Re: Function to check duplicate values in multiple response

Posted: February 9th, 2013, 6:26 pm
by lls
Do this work for you?

Code: Select all

do i = 1 while i < curocc()
		if $(i) = $ then
			errmsg("Value %d already in position # %d",$,i);
			reenter;
		endif;
	enddo;

Re: Function to check duplicate values in multiple response

Posted: February 10th, 2013, 2:35 pm
by hannesrr
I think this code must be enough and this works only in data entry

proc MULT_FIELD

intActualValue=$;

if count(MULT_FIELD where MULT_FIELD=intActualValue) then
errmsg("This value has been entered");
reenter;
endif;

Re: Function to check duplicate values in multiple response

Posted: February 14th, 2013, 3:28 pm
by Gregory Martin
lls and hannesrr both present reasonable ways to check to see if a value is duplicated in a repeating item. There is no CSPro function that can automatically return to you whether or not there was a duplicate across the items.

You could use hannesrr's code but you would have to change the code to say count(...) > 1. Count will always return 1 because there will always be at least one instance of the value (i.e., the just-entered value!).

You could also write:
proc MULT_FIELD

    intActualValue = $;

    
if seek(MULT_FIELD = intActualValue) < curocc() then
        
errmsg("This value has been entered");
        
reenter;
    
endif;