I would like to write a validation condition that sums the responses to 4 questions and check if it is less than equal to100. But I want to sum only if the response to the each of the above questions is positive. The simple syntax for the condition seems like I have to write out all combinations - cases for each time one of the variable is not positive as well. Is there a way around this?
Perhaps, you could express this idea in the Cspro or SurveyCTo language, and then we could convert it to Survey Solutions together?
I don’t know either.
Something like this:
(Q1+Q2+Q3+Q4)<=100 if Q1>=0 or Q2>=0 or Q3>=0 or Q4>=0. But if Qx <0 then it should be treated as 0.
The two statements above are contradictive.
If you are talking about the shares, then the checks are:
- each share is >=0 or a special value
- each share is <=100
- sum <=100 (under presence of special values, like “don’t know”)
For the case of two proportions x and y, I envision the last condition being:
x>0?x:0 + y>0?y:0<=100
provided that the responses have been given already.
How would this handle the case where a variable is unanswered (and thus, for C#,
x>0 be evaluated as
false and the expression resolve to
0? Or do we need the null-coallescing operator in the expression like this
I’m always following new Survey Solution release to see when it will allow us to port or import existing librairies of functions from other CAPI platform. Several users request on this forum are already solved on CSPro.
Please let’s know!
Do you mean CSPro now imports Survey Solutions syntax??
@sergiy, As you know, CSPro is very open, so, several expressions designed using Survey Solutions syntax can be ported to his powerful language who’s C derived and developed for more than 35 years (From ISSA and IMPS). I’m writing about supporting of user designed functions and if, for, do statements in a friendly GUI compiler as requested by multiple users on Survey Solutions. Without theses improvements, it’s impossible to port existing CSPro librairies to Survey Solutions users designed questionnaire application…
Just to try illustrating what you want.
Here is the solution in Cspro.
I used this solution for a similar case.
You first need to have functions to add positive numbers and negative numbers. I assume you have -ve values to handles NA and Dont knows.
You write this at global level
//Adding Positive numbers
if value = -9 then IgnoreNA = 0;
else IgnoreNA = value;
//Adding –ve numbers
if value>=0 then AddNA= 0;
else AddNA = value;
Then at the end of the fourth variable you can write this:
numeric myposSum = IgnoreNA(Q1) + IgnoreNA(Q2) + IgnoreNA(Q3) + IgnoreNA(Q4);
numeric mynegSum = IgnoreNA(Q1) + IgnoreNA(Q2) + IgnoreNA(Q3) + IgnoreNA(Q4);
///You are checking if mypossum is >100. Why? Because if we say <> 100 what about the case whereby there is a –ve. Assuming that we have -9 as don’t know in one of the variables it means our total should not be 100 to cater for the unknown.
if mySum>100 then errmsg(“Q1to Q4 should add up to 100%, Please verify your figures.Current total is %d”,mySum);
///// Then check if we have –ve and 100 at the same time. This should not be possible.
If mynegsum<-1 and mypossum=100 then errmsg(WE CANT HAVE DONT KNOWS AND 100% AT THE SAME TIME)
Here are some things you should consider too if applicable.
- YOU CANT HAVE DONT KNOWS(-ve numbers) AND 100% AT THE SAME TIME
- YOU CANT HAVE ONE ATTRIBUTE WITH DONT KNOW(-ve), IT CAN BE A ZERO OR THE DIFFERENCE OF THE SUM OF OTHER ATTRIBUTES FROM 100"
So using this , A Survey solutions official can now give a detailed assistance.
I have already provided a solution to the question of the original poster @tbalantrapu about how to verify the sum being less than a total in the presence of missing values. I assume the silence confirms the solution.
Subsequently @htuser has written that he (she) is waiting for “it will allow us to port or import existing libraries of functions from other CAPI platform”.
This is where I became interested in seeing an example of How CSPRO imports procedures from other CAPI systems, for example Survey Solutions, but could be anything else.