How to combine two IsNull condition in IF expression in Qlikview? - if-statement

I have three column as A, B, C
I'm writing an expression for column D in Qlikview to find out whenever column B & C IsNull I need to replace the value of C in column D. Similarly Vice versa for the remaining columns.
Expression:
=if((IsNull(A) and IsNull(B)), C,if((IsNull(B) and IsNull(C)), A,.....)
But I'm not getting the values in my output.
Was there any issue in the above expression ?
Can someone help me on it .

try
if (rangesum(len(A),len(B))=0,C,if (rangesum(len(B),len(C))=0,A,.....
isNull is a problematic functions and many times does behave as expected.
It is best practice to use Len() instead.
also make sure you have a single value in A,B,C per row, otherwise it will not work

Related

What is the difference between (a+b)* and (a*b*)*?

Assuming that Σ = {a, b}, I want to find out the regular expression (RE) Σ* (that being the set of all possible strings over the alphabet Σ).
I came up with below two possibilities:
(a+b)*
(a*b*)*
However, I can't decide by myself which RE is correct, or if both are bad. So, please tell me the correct answer.
The + operator is typically used to indicate union (|, "or") in academic regular expressions, not "one or more" as it typically means in non-academic settings (such as most regex implementations).
So, a+b means [ab] or a|b, thus (a+b)* means any string of length 0 or more, containing any number of as and bs in any order.
Likewise, (a*b*)* also means any string of length 0 or more, containing any number of as and bs in any order.
The two expressions are different ways of expressing the same language.
In normal regular expression grammar, (a+b)* means zero or more of any sequence that start with a, then have zero or more a, then a b. This discounts things like baa (it doesn't start with a), abba, and a (there must be one exactly b after each a group), so is not correct.
(a*b*)* means zero or more of any sequence that contain zero or more a followed by zero or more b. This is more correct since it allows for either starting character, any order and quantity of characters, and so on. It also allows the empty string which I'm pretty certain should be allowed by Σ* (but I'll leave that up to you).
However, it may be better to opt for the much simpler [ab]* (or [ab]+ in the unlikely event you consider an empty string invalid). This is basically zero (one for the + variant) or more of any character drawn from the class [ab].
However, it's possible, since you're using Σ, that you may be discussing formal language theory (where Σ is common) rather than regex grammar (where it tends not to be).
If that is the case then you should understand that there are variants of the formal language where the a | b expression (effectively [ab] in regex grammar) can instead be rendered as one of a ∪ b, a ∨ b or a + b, with each of those operator symbols representing "logical or".
That would mean that (a+b)* is actually correct (as it is equivalent to the regex grammar I gave above) for what you need since it basically means any character from the set {a, b}, repeated zero or more times.
Additionally, that's also covered by your (a*b*)* option but it's almost always better to choose the simplest one that does the job :-)
And just something else to keep in mind for the formal language case. In English (for example), "a" is a word but you'd struggle to find anyone supporting the possibility that "" is also a word. Try looking it up in a dictionary :-)
In other words, any regular expression that allows an empty sequence of the language characters (such as (a+b)*) may not be suitable. You may find that (a+b)(a+b)* is a better option. This depends on whether Σ* allows for the empty sequence.
Acording to the algebraic properties of regular expressions,
(a*b*)* = (a+b)*
Therefore (a+b)* = (a*b*)*
Extra information:
(a+b)* = L(a+b)*
= (L(a+b))*
= (L(a) U L(b))*
= ({a} U {b})*
= {a,b}*
= {ε, a, b, aa, bb, ab, abab, aba, bbba,...}

SAS logical operators help (if at least two are true then...)

SAS question. I am creating a variable where if different logic rules are met it takes on one of two values. Let's say the binary variable I'm creating is RiskScore and there are three conditions A, B, and C that determine which risk score an observation takes on. How would I do this in SAS?
Condition A: Age > 70
Condition B: Cholesterol > 200
Condition C: Has diabetes
If at least two of conditions A, B, or C are TRUE then RiskScore=High;
Else RiskScore=Low;
Thanks for your help!
In SAS true/false are 1/0, so if you add up your conditions and it's greater than
or equal to 2 then you're good to go.
if sum(age>70, chol>200, diabetes=1)>=2 then do;

Google sheet, keyword to return the value of the parameter of the logical expression in IF Formula?

In IF statement is it possible to return the value of the parameter of the logical expression with some keywords instead of rewriting the parameter?
The reason is that for nested if statements it would be very useful.
I've tried to explain it as better as possible in English but I suppose that the best way is an example.
An example is:
This is using the parameter of the logical expression:
=IF('MySecondSheet'!C21>0, 'MySecondSheet'!C21, false)
This is the same but using an hypothetical keyword that I will call "this"
=IF('MySecondSheet'!C21>0, this, false)
Is it possible in some way?
Thanks,
I don't think this is possible. In fact, I don't think it would be sensible to develop such functionality because it is a very particular use case. Suppose you were comparing with another cell value instead of a constant.
=IF('MySecondSheet'!C21>'MyfirstSheet'!A1, this, "text")
Which value would this refer to now? Furthermore, suppose you have a more complicated formula
=IF(A1 * A1 - A2 < A3, this, "text")
Again, it is not obvious whether this would return the left-hand side of the relation or one of the cell values.
If you name C21 in MySecondSheet this then something like:
=IF(this>0,this,"false")
should work.

Regular expression: sequences

Stuck with a silly problem. I have an input field, where user can input limited amount of letters (ABCDEFG). Here is the problem: I do not want users to be able to have more than 3 A, C, E and G's letters in a single subsequence of the input, that is: no AAA, CCC, EEE, GGG. And the second thing is almost the same as the first one: no more than 1 B, D, F in a single subsequence, that is: no BB, DD, FF. These two rules are somehow to be combined together.
So, for example, AABFGECC is valid. GEFFFAABG is invalid.
Hope, you will help me! Thank you!
P.S If it is important, I am writing my app in Visual Basic. But I think, this is not so important.
What if you made an expression which matches the cases you want to avoid and instead check that the input does not match? Like this:
([^A-F]|AAA|CCC|EEE|GGG|BB|DD|FF)
While you could be clever and use back-references, a simple solution is to black-list the invalid sequences using a negative look ahead:
^(?!.*(?:AAA|CCC|EEE|GGG|BB|DD|FF))[A-G]*$
Logically, that is the same has having those 7 invalid sequences in a list, and checking the string does not contain either one, which also gives you a nice alternative.

Equivalence of boolean expressions

I have a problem that consist in comparing boolean expressions ( OR is +, AND is * ). To be more precise here is an example:
I have the following expression: "A+B+C" and I want to compare it with "B+A+C". Comparing it like string is not a solution - it will tell me that the expressions don't match which is of course false. Any ideas on how to compare those expressions?
Any ideas about how can I tackle this problem? I accept any kind of suggestions but (as a note) the final code in my application will be written in C++ (C accepted of course).
An normal expression could contain also parenthesis:
(A * B * C) + D or A+B*(C+D)+X*Y
Thanks in advance,
Iulian
I think the competing approach to exhaustive (and possibly exhausting) creation of truth tables would be to reduce all your expressions to a canonical form and compare those. For example, rewrite everything into conjunctive normal form with some rule about the ordering of symbols (eg alphabetical order within terms) and terms (eg alphabetical by first symbol in term). This of course, requires that symbol A in one expression is the same as symbol A in another.
How easy it is to write (or grab from the net) a C or C++ function for rewriting your expressions into CNF I don't know. However, there's been a lot of AI work done in C and C++ so you'll probably find something when you Google.
I'm also a little unsure about the comparative computational complexity of this approach and the truth-table approach. I strongly suspect that it's the same.
Whether you use truth tables or a canonical representation you can of course keep down the work to be done by splitting your input forms into groups based on the number of different symbols that they contain.
EDIT: On reading the other answers, in particular the suggestion to generate all truth tables and compare them, I think that #Iulian has severely underestimated the number of possible truth tables.
Suppose that we settle on RPN to write the expressions, this will avoid having to deal with brackets, and that there are 10 symbols, which means 9 (binary) operators. There will be 10! different orderings of the symbols, and 2^9 different orderings of the operators. There will therefore be 10! x 2^9 == 1,857,945,600 rows in the truth table for this expression. This does include some duplicates, any expression containing only 'and' and 'or' for instance will be the same regardless of the order of symbols. But I'm not sure I can figure this any further ...
Or am I making a big mistake ?
You can calculate the truth table for each expression over all possible inputs then compare the truth tables.