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
- /
- General Programming
- /
- Array help

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

10-23-2016 02:12 AM

Hello,

I am stuck at where I need to find the ith observation which is equal to the ith observation + 90. For example if my i=1 value is 2, then I need to find m?, where the value would be 2+90 = 92.

I am using this code.

data x;

set y;

array help(*) 1-370;

do i = 1 to 370;

do m = 1 to 370;

if help(i) + 90 = help(m) then leave;

end;

run;

Thank you

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

10-23-2016 02:29 AM

You don't need two loops.

Can you have multiple matches?

The WHICHN function can return the index of an array that contains the value you're looking for.

Do i = 1 to 370;

x=whichnhelpv(I)+ 90, of help(*));

if x>0 then leave;

end;

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

10-23-2016 04:59 AM

It seems like a typo defining: **array help(*) 1-370;**

You probably meant, something like: array help(*) **v1-v370;**

@Reeza you meant to write (missed open bracket):

x=whichn**( **helpv(I)+ 90, of help(*) );

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

10-23-2016 05:29 AM

@Shmuel Eagle eyes! Thanks!

```
Do i =1 to 370;
X = whichn(help(I) + 90, of help(*));
If x > 0 then leave;
End;
```

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

10-23-2016 11:37 AM

Thank you so much for the help. The codes worked, however I want x-i to be less than 180. If x-i crosses 180 then I would want to select that value of i which would give me x-i<180.

Thanks once again

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

10-23-2016 12:41 PM

Please illustrate your problem with sample data amd expected output.

If you have any other restrictions make sure to highlight them.

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

10-24-2016 11:05 AM

Please find a sample dataset

It is a dataset of students and their attendance, which is cumulative over 12 days. I need to find the earliest day when their attendance crossed 5 days over a period of 7 days. Thank you

ID | Day1 | Day2 | Day3 | Day4 | Day5 | Day6 | Day7 | Day8 | Day9 | Day10 | Day11 | Day12 |

Robin | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |

Michael | 1 | 2 | 2 | 3 | 4 | 5 | 5 | 6 | 7 | 8 | 9 | 10 |

Jeremy | 1 | 2 | 3 | 3 | 4 | 5 | 6 | 6 | 7 | 7 | 7 | 7 |

Matt | 1 | 1 | 1 | 2 | 2 | 3 | 3 | 3 | 4 | 4 | 5 | 6 |

Sara | 1 | 2 | 3 | 4 | 5 | 5 | 5 | 6 | 6 | 7 | 8 | 9 |

Tony | 1 | 2 | 2 | 2 | 2 | 3 | 3 | 3 | 4 | 4 | 4 | 4 |

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

10-24-2016 12:53 PM

What is the expected output for data?

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

10-24-2016 01:03 PM

Expected output

Name Start_day Day_crossing_5

Robin 1 5

Michael 1 6

Jeremy 1 6

Matt 5 12

Sara 1 5

Tony . .

It does not need to be the first day, if using the first day at start_date does not give the answer, then I want the program to move to the next one. In this way the start_day for Matt reached 5, because on day12 his value was 5 greater than the value(2) on day5. So over a period of 7days he crossed 5 attendace units. If you would have used day1 as start date for Matt, he would have reached only 3 by day 7. Does that help ?

Thanks,

Divyan

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

10-24-2016 04:33 PM - edited 10-24-2016 04:34 PM

You are posting a very similar situation to your previous question.

Here is @Reeza's solution addapted to your last post:

`array dayx day1-day12;`

Do i =1 to 12;
X = whichn(dayx(I) > 5 , of dayx(*));
If x > 0 then leave;
End;

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

10-24-2016 07:29 PM

Thank you for the answer, but then how would I restrict my lookup period to 7 days. I do not want to include any observations if they occur after 7 days.

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

10-24-2016 08:52 PM

I'm not sure I understand what you mean.

Anyhow, you can filter the output by adding a line after END of the DO loop, like:

IF i > 7 then delete;