Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- Help needed with outputting data using Data Step

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

07-28-2017 11:03 AM - edited 07-28-2017 11:05 AM

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

Accepted Solutions

Solution

07-31-2017
12:59 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to jos283

07-28-2017 11:22 AM

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;`

All Replies

Solution

07-31-2017
12:59 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to jos283

07-28-2017 11:22 AM

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;`

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to jos283

07-29-2017 09:12 PM

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;
```