I have a dataset like below, and want to collapse a subject so that I can see if they were diagnosed with a disease at all within the past 3 years using SAS. Disease1-3 are binary yes/no flags.
For example - for subject a in 2021, since they had all 3 diseases in the prior year of 2020, they should also have flags for all those diseases in 2021 and 2022.
| subject | year | disease1 | disease2 | disease 3 |
|---|---|---|---|---|
| a | 2020 | 1 | 1 | 1 |
| a | 2021 | 0 | 0 | 0 |
| a | 2022 | 0 | 0 | 0 |
| b | 2020 | 0 | 1 | 0 |
| b | 2021 | 1 | 0 | 0 |
| b | 2022 | 0 | 0 | 1 |
I'm hoping it would look something like this.
| subject | year | disease1 | disease2 | disease 3 |
|---|---|---|---|---|
| a | 2020 | 1 | 1 | 1 |
| a | 2021 | 1 | 1 | 1 |
| a | 2022 | 1 | 1 | 1 |
| b | 2020 | 0 | 1 | 0 |
| b | 2021 | 1 | 1 | 0 |
| b | 2022 | 1 | 1 | 1 |
What would be the best way about going to do this? I've tried using a do loop and the retain statement, but get stuck due to the fact that there are multiple columns to consider (disease1-disease3).