I have the following code and clearly I am not doing something right.
The value of Rule3 is return the value of "No", therefore I want the value of "
RegOff" to be "No", but if the value of Rule3 is "Yes", then apply the and plus or statements.
Sorry if this is an easy one, but perhaps I've been looking at it too long and my head is going in circles.
if 'INT Type'n =1 and RGO=1 or IDF=1 then Rule3="Yes"; else Rule3="No"; if Rule3="Yes" and ADM >0 or ALC >0 or CAR>0 or CDM >0 or MPR >0 or NCP >0 or PTR >0 or DMA >0 or DMC >0 or IDD >0 Then RegOff="Yes"; else RegOff="No";
IF is a statement, OR is an operator.
In logic, AND takes precedence over OR. Therefore your conditions are equivalent to this:
if ('INT Type'n =1 and RGO=1) or IDF=1 then Rule3="Yes"; if (Rule3="Yes" and ADM >0) or ALC >0 or CAR>0 or CDM >0 or MPR >0 or NCP >0 or PTR >0 or DMA >0 or DMC >0 or IDD >0 then RegOff="Yes";
My examples are only there to illustrate what your conditions as posted really do.
It is now up to you to set the parentheses in a way so that the code reflects what you want to achieve.
If all the ORs in a compound condition should only play a role if the first condition is met, you need to do
if a and (x or y or z)
Review both of your IF statements in light of this.
Hint: if you have many numeric variables and you want to find if any (one or more) of them have a value greater than 0 you can reduce code like this (Assuming the intent is to use all of them to get one logical result)
ADM >0 or ALC >0 or CAR>0 or CDM >0 or MPR >0 or NCP >0 or PTR >0 or DMA >0 or DMC >0 or IDD >0
max( ADM, ALC, CAR, CDM, MPR, NCP, PTR, DMA, DMC, IDD)>0
You would have to provide values of the variables, the incorrect result and the expected result for the values to determine the actual issues in your comparison approach.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.