turn on suggestions

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
- /
- Base SAS Programming
- /
- how do i do this with as few steps as possible?

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
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-09-2017 07:14 AM - edited 02-09-2017 07:21 AM

i have a database that looks like this

id | diag 1 | diag2 | diag3 | diag4 | diag5 | diag7 | diag8 | diag9 |

1 | 1 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |

2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |

3 | 0 | 0 | 0 | 0 | 1 | 1 | ||

4 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |

I need to create a new_var that is equals to 1 if either one of the 'diag's have a value of 1.

I did it by summing the diags and having the new_var = 1 if sum(diag1-diag24)>=1.

Is there another way to do this without typing a lot? Also, my technique only works if the observantions are 1s and 0s. I could do something like this if my obs values were different than 1 --> diag1=2 or diag2=1 or diag3=5....and so on then new_var=1. This isn't very practical when i have many 'diag's, so how could I do this without typing a lot?

Accepted Solutions

Solution

03-10-2017
10:00 AM

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

02-09-2017 07:49 AM - edited 02-09-2017 08:16 AM

Finding only a 1 (not a 2 or a 5) can be done with only mild complications. The CAT family of functions works on numeric as well as character values. So you could code:

if index(cats(of diag1-diag24), '1') > 0;

If your data contains two-digit numbers (so you need to find "1" but not "10"), it can still be done but gets mildly more complex.

All Replies

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

02-09-2017 07:18 AM

I think your solution is solid, though you would probably type sum(of diag1-diag24)>=1

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

02-09-2017 07:21 AM

good catch! thanks

Solution

03-10-2017
10:00 AM

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

02-09-2017 07:49 AM - edited 02-09-2017 08:16 AM

Finding only a 1 (not a 2 or a 5) can be done with only mild complications. The CAT family of functions works on numeric as well as character values. So you could code:

if index(cats(of diag1-diag24), '1') > 0;

If your data contains two-digit numbers (so you need to find "1" but not "10"), it can still be done but gets mildly more complex.

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

02-09-2017 11:14 AM

For a very few character shorter typing:

new_var = (index(catt(of diag,'1')>0);

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

02-09-2017 09:00 AM

sum(of diag1-diag9) >=1 OR max(of diag1-diag9) >=1 should work.