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

Here I have a bunch of Checks to output if they equal 1. Each check that is equal to 0 should be ignored.

 

This is the current code I have for the output:

Data ouput_file;
    Set input_file;
    If first_check = 1;
       If second_check = 1;
          If third_check = 1;
             If fourth_check = 1;
                 If fifth_check = 1 then output;
Run;

 

At the moment, the code only works assuming that first_check = 1. The problem I am facing is that if first_check = 0, the code won't run. If first_check = 0, I still want it to ouput the other checks if they are equal to 1.

 

How do I get it to run for all checks when they are equal to 1 assuming any check (i.e the first or second) can be 0?

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You're conditions are stacked, like they have an AND. It looks like you want OR instead, if any is one then outout?

If so, you can simplify this by checking if the sum of the values are greater than or equal to 1. 

 

if sum(first_check, second_check, .. , fifth_check) >= 1 then output;

View solution in original post

2 REPLIES 2
Reeza
Super User

You're conditions are stacked, like they have an AND. It looks like you want OR instead, if any is one then outout?

If so, you can simplify this by checking if the sum of the values are greater than or equal to 1. 

 

if sum(first_check, second_check, .. , fifth_check) >= 1 then output;
Patrick
Opal | Level 21

@jos283

The syntax (sub-setting IFs) you've used translate logically into AND. What you're after is OR.

If you're variables numeric and flags (0/1) then the logic @Reeza posted will work; else use something as below:

data ouput_file;
  set input_file;
  if 
    first_check = 1 
    or second_check = 1 
    or third_check = 1 
    or fourth_check = 1 
    or fifth_check = 1 
    then output;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2 replies
  • 635 views
  • 0 likes
  • 3 in conversation