Hi All,
I have the below logic and confused on how to include 'AND 'and 'OR' within same if statement.
If
((HAT = 'Yes' Or SAT = 'Yes' Or TBP = 'Yes') Or (TBI = 'Yes' And REC = 'Yes') Or COT = Yes) And
RESULT = 'Pos' And Does not satisfy (CAT = 'XCL' and TEST = 27) then output
The above variables with given values should satisfy so that i get the desired output from the given raw data.
Any help with how to write the program to satisfy the logic?
Questions like this is much easier to answer if you provide a minimum of sample data and your desired result.
Thanks for your reply @PeterClemmensen
Please consider the below data as the raw data. Consider the first column as ID and rest are the variables in order HAT SAT TBP TBI REC COT RESULT CAT TEST with corresponding values
202359 No No No No Yes Pos XCL 26.0
202360 Yes Yes Yes Yes Yes Yes Pos XCL 27.0
202360 Yes Yes Yes Yes Yes Yes Pos ICL 27.0
My output should be the below record not the rest.
202359 No No No No Yes Pos XCL 26.0
@r3570 wrote:
Please consider the below data as the raw data. Consider the first column as ID and rest are the variables in order HAT SAT TBP TBI REC COT RESULT CAT TEST with corresponding values
202359 No No No No Yes Pos XCL 26.0
202360 Yes Yes Yes Yes Yes Yes Pos XCL 27.0
202360 Yes Yes Yes Yes Yes Yes Pos ICL 27.0
My output should be the below record not the rest.
202359 No No No No Yes Pos XCL 26.0
In your first post, your criteria included
And Does not satisfy (CAT = 'XCL' and TEST = 27)
which, as @ballardw said, would be expressed as
NOT (CAT = 'XCL' and TEST = 27)
But that would not produce a single output as you want. There would be 2 output observations from this condition. So what do you mean by
And Does not satisfy (CAT = 'XCL' and TEST = 27)
Hi,
If I've understood your requirements, for the record you want I have created the following code. Is this what you're looking for?
data have;
input
@01 id $char6.
@08 HAT $char3.
@12 SAT $char3.
@16 TBP $char3.
@20 TBI $char3.
@24 REC $char3.
@28 COT $char3.
@32 RESULT $char3.
@36 CAT $char3.
@40 TEST 8.
;
datalines;
202359 No No No No Yes Pos XCL 26.0
202360 Yes Yes Yes Yes Yes Yes Pos XCL 27.0
202360 Yes Yes Yes Yes Yes Yes Pos ICL 27.0
;
data want;
set have;
if (
(HAT = 'Yes' or SAT = 'Yes' or TBP = 'Yes')
or (TBI = 'Yes' and REC = 'Yes')
or COT = 'Yes'
)
and RESULT = 'Pos'
and CAT = 'XCL'
and TEST = 26
;
run;
Thanks & kind regards,
Amir.
"And Does not satisfy (CAT = 'XCL' and TEST = 27)"
would be
And Not (CAT = 'XCL' and TEST = 27) )
NOT is an operator to negate the result of a logical operation. If (CAT = 'XCL' and TEST = 27) is "true" then not(CAT = 'XCL' and TEST = 27) is "false".
With out know the expected result for some given values it is hard to tell if the rest of your logic is correct or not.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.
Ready to level-up your skills? Choose your own adventure.