Page 1 of 1

Error message for incompatible multiple answers

Posted: July 4th, 2017, 11:50 am
by claudia
Hi,
I was wondering how to create an error message in case some incompatible answers are selected in a question allowing for multiple answers; e.g.

Q1: What kind of healthcare professional(s) did you consult?

A- family doctor
B- gynaecologist
C- phisiotherapist
D- none

Answer "D" is incompatible with any other answer.

Many thanks!

Re: Error message for incompatible multiple answers

Posted: July 4th, 2017, 12:45 pm
by khurshid.arshad
Dear claudia;

variablename Data type should be Alpha in Dictionary
Field property will be "Check box" in the form design

The syntax will be:

Code: Select all

Proc variablename

If pos(“D”,$) >=1 and length (strip(($))>1  then 
	Errmsg (“You can not select “None” with other options.”)
	$=””;
	Reenter;
Else
Endif;

a.

Re: Error message for incompatible multiple answers

Posted: July 5th, 2017, 9:29 am
by claudia
That's incredibly helpful thanks!

In case anyone uses the same command, I had to modify a couple of details because my cspro wasn't happy about an extra braket and some inverted commas, so this is what I used:

if pos("D",$) >=1 and length (strip($))>1 then
errmsg ("You cannot select none at the same time as other options");
$="";
Reenter $;
Else
Endif;

I have an additional question:
how does the command change if I have two or three options which can only be selected by themselves? Eg.

Q1: What kind of healthcare professional(s) did you consult?

A- family doctor
B- gynaecologist
C- phisiotherapist
D- none
E- don't know

In this case, answers "D" and "E" are incompatible with any other answer.

Thank you!

Re: Error message for incompatible multiple answers

Posted: July 5th, 2017, 10:42 am
by sah
If i should understand you well, that you cannot select the two option at same time then ....

Code: Select all

if pos("D", $) >= 1 then
     errmsg (“You can not select “None” with other options.”)
 reenter;
elseif pos("E", $) >= 1 then
   errmsg("You can not select 'DK,with other options");
 reenter;
endif;

Re: Error message for incompatible multiple answers

Posted: July 6th, 2017, 10:53 am
by claudia
Thanks for your reply.

The code worked fine to create an error message if someone selects options "D" and "E" at the same time. However, I was also looking for an error message in case someone selects for ex. A, B, and E (seen as it's incompatible to say you consulted a healthcare professional AND you don't know). How do I create a command for this?

I also have another multiple answer question where there are 3 answer possibilities (D-F) which are incompatible with the other options (A-C): e.g.

A- family doctor
B- gynaecologist
C- phisiotherapist
D- "none"
E- "don't know"
F- "Not applicable"


Could you kindly advise for a command in this last case too?

Re: Error message for incompatible multiple answers

Posted: July 6th, 2017, 11:34 am
by khurshid.arshad
Dear claudia;

Code: Select all

if pos("D", $) >= 1 then
     errmsg (“You can not select “None” with other options.”)
 reenter;
elseif pos("E", $) >= 1 and length(strip($)>1 then
   errmsg("You can not select 'DK,with other options");
 reenter;
endif;
In this case you can not select E with other options.

Code: Select all

if poschar("DEF", $) >= 1  and length (Strip($)>1 then
     errmsg (“Invalid entry.”)
$="";
 reenter;
endif;
It means D, E, F can only be selected as single option.

a.

Re: Error message for incompatible multiple answers

Posted: July 7th, 2017, 4:55 am
by claudia
Perfect, that's what I was looking for. Thanks