Function to check duplicate values in multiple response vari

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
Bharadwaj

Function to check duplicate values in multiple response vari

Post 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
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 »

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: 55
Joined: January 8th, 2013, 5:02 pm
Location: Lima, Perú, South America

Re: Function to check duplicate values in multiple response

Post 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;
Hannes Rodriguez :geek:
Lima, Perú
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Function to check duplicate values in multiple response

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