BookmarkSubscribeRSS Feed
ybz12003
Rhodochrosite | Level 12

Hello,

I have codes shown as below,  I am wondering if I could simply the WHERE condition better.

 

proc sql;
	create table lab&rr as
 	select studysite,caseid,PCR,H3N2,FluA,FluAH1,FluAsub1,FluAsub2  
 	from ds3	
	where PCR = 1 and (H3N2 = 1 or FluA = 1 or FluAH1 =1)  
		and ((FluAsub2 ne 1 and FluAsub1 ne 1) or (FluAsub2 = 1 and FluAsub1 = 0)  or (FluAsub2 = 0 and FluAsub1 = 1) )
 	order by studysite,caseid;

I feel the coding which is looking for either FluAsub1 or FluAsub2 is positive, is kind of long.  I am not sure if there is a better way to write it.  Thanks.

 

(FluAsub2 ne 1 and FluAsub1 ne 1) or (FluAsub2 = 1 and FluAsub1 = 0)  or (FluAsub2 = 0 and FluAsub1 = 1)

 

4 REPLIES 4
PaigeMiller
Diamond | Level 26

How about

 

FluAsub2 + FluAsub1 < 2
--
Paige Miller
Reeza
Super User
(FluAsub2 ne 1 and FluAsub1 ne 1) or (FluAsub2 = 1 and FluAsub1 = 0)  or (FluAsub2 = 0 and FluAsub1 = 1)

I get the last two of those conditions since either can be 1, should the first condition be ne though? Are you looking for either = 0 or either  = 1? Typically it's 1, which means that should be eq not ne in the first condition?

 

You're either looking for:

 

not(fluAsub2 or fluAsub1)

 or 

(fluAsub2 or fluAsub1)
Patrick
Opal | Level 21

If I understand the condition right then you want to exclude the case where FluAsub1 = 1 and FluAsub2 = 1

 

and NOT (FluAsub1 = 1 and FluAsub2 = 1)

Or as a boolean expression (assuming these are flags with either 1 or 0)

and not (FluAsub1 and FluAsub2)

or...

and (not FluAsub1 or not FluAsub2)
s_lassen
Meteorite | Level 14

That depends.

If your variables can only be 1 or 0, it can be simplified, e.g. to "not (FluAsub1 and FluAsub2)".

But if your code is written like that because one or both of them can be e.g. 8, -2342 or perhaps missing, then probably not.

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 596 views
  • 0 likes
  • 5 in conversation