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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 514 views
  • 0 likes
  • 3 in conversation