Function to check duplicate values in multiple response vari

Discussions about CSEntry
Post Reply
Bharadwaj

Function to check duplicate values in multiple response vari

Post by Bharadwaj » February 9th, 2013, 2:35 pm

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

lls
Posts: 109
Joined: December 6th, 2011, 3:11 pm
Location: Geneva, Switzerland

Re: Function to check duplicate values in multiple response

Post by lls » February 9th, 2013, 6:26 pm

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;

hannesrr
Posts: 41
Joined: January 8th, 2013, 5:02 pm

Re: Function to check duplicate values in multiple response

Post by hannesrr » February 10th, 2013, 2:35 pm

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;
Hannes Rodriguez :geek:

Gregory Martin
Posts: 1338
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Function to check duplicate values in multiple response

Post by Gregory Martin » February 14th, 2013, 3:28 pm

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;

Post Reply