BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PharmlyDoc
Quartz | Level 8

I would like to see if multiple columns all contain '0' without having to use multiple 'AND' Statements.

It would ultimately be used within a CASE WHEN statement. 

 

Proc SQL;
select
PAT_ID,
COL2, COL3, COL4, COL5, COL6, COL7,
CASE WHEN ((COL3 = 0) AND (COL4=0) AND (COL5=0) AND (COL6=0) AND (COL7=0)) THEN 1 ELSE 0 END ZEROS
FROM data;
quit;
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Mathematical logic alternatives

 

  • Max of the series = Min of the series = 0
  • Range =0 and any value = 0
  • Add values and check if sum is 0
  • Use WHICHN to search for 1, if the alternative values are 1. If they're something else this option doesn't work

The third option is probably the easiest. If you run into floating point errors you may want to use a ROUND to ensure it doesn't happen or FUZZ but the idea is as follows:

 

CASE WHEN sum(col3, col4, col5, col6, col7) = 0THEN 1 ELSE 0 END ZEROS

 

 


@PharmlyDoc wrote:

I would like to see if multiple columns all contain '0' without having to use multiple 'AND' Statements.

It would ultimately be used within a CASE WHEN statement. 

 

Proc SQL;
select
PAT_ID,
COL2, COL3, COL4, COL5, COL6, COL7,
CASE WHEN ((COL3 = 0) AND (COL4=0) AND (COL5=0) AND (COL6=0) AND (COL7=0)) THEN 1 ELSE 0 END ZEROS
FROM data;
quit;

 

View solution in original post

1 REPLY 1
Reeza
Super User

Mathematical logic alternatives

 

  • Max of the series = Min of the series = 0
  • Range =0 and any value = 0
  • Add values and check if sum is 0
  • Use WHICHN to search for 1, if the alternative values are 1. If they're something else this option doesn't work

The third option is probably the easiest. If you run into floating point errors you may want to use a ROUND to ensure it doesn't happen or FUZZ but the idea is as follows:

 

CASE WHEN sum(col3, col4, col5, col6, col7) = 0THEN 1 ELSE 0 END ZEROS

 

 


@PharmlyDoc wrote:

I would like to see if multiple columns all contain '0' without having to use multiple 'AND' Statements.

It would ultimately be used within a CASE WHEN statement. 

 

Proc SQL;
select
PAT_ID,
COL2, COL3, COL4, COL5, COL6, COL7,
CASE WHEN ((COL3 = 0) AND (COL4=0) AND (COL5=0) AND (COL6=0) AND (COL7=0)) THEN 1 ELSE 0 END ZEROS
FROM data;
quit;

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 1 reply
  • 858 views
  • 0 likes
  • 2 in conversation