Good afternoon fellow SAS users and communities,
I have a question concerning the identification of episodes of an illness/outcome using data at the level of patient-weeks. Using the hypothetical data below (two patients), every time a binary event occurs, I am interested in flagging/counting the continuous episode of high-cost associated with that event. The variable I am interested in deriving is called "episode". When the high_costs=1 stop, then the episode should stop as well. Once the event=1 starts up again, another episode is occurring and high costs are assessed again. A new episode cannot start until the high_cost returns to 0 (see patient 2). Ultimately, I want to know the episode number of a particular week.
Would anyone be able to help out with this?
Thanks in advance,
-Carmie
Subject_id | Week | Event | High_cost | Episode |
1 | 1 | 1 | 1 | 1 |
1 | 2 | 0 | 1 | 1 |
1 | 3 | 0 | 1 | 1 |
1 | 4 | 0 | 1 | 1 |
1 | 5 | 0 | 1 | 1 |
1 | 6 | 0 | 1 | 1 |
1 | 7 | 0 | 0 | 0 or deleted |
1 | 8 | 0 | 0 | 0 or deleted |
1 | 9 | 0 | 0 | 0 or deleted |
1 | 10 | 0 | 0 | 0 or deleted |
1 | 11 | 1 | 1 | 2 |
1 | 12 | 0 | 1 | 2 |
1 | 13 | 0 | 1 | 2 |
1 | 14 | 0 | 0 | 0 or deleted |
1 | 15 | 0 | 0 | 0 or deleted |
1 | 16 | 0 | 0 | 0 or deleted |
1 | 17 | 0 | 0 | 0 or deleted |
1 | 18 | 0 | 0 | 0 or deleted |
2 | 1 | 1 | 1 | 1 |
2 | 2 | 0 | 1 | 1 |
2 | 3 | 0 | 1 | 1 |
2 | 4 | 1 | 1 | 1 |
2 | 5 | 0 | 1 | 1 |
2 | 6 | 0 | 0 | 0 or delete |
2 | 7 | 0 | 0 | 0 or delete |
2 | 8 | 1 | 1 | 2 |
2 | 9 | 0 | 0 | 0 or delete |
2 | 10 | 0 | 0 | 0 or delete |
2 | 11 | 0 | 0 | 0 or delete |
data have;
input Subject_id
Week
Event
High_cost
Episode ;
cards;
1
1
1
1
1
1
2
0
1
1
1
3
0
1
1
1
4
0
1
1
1
5
0
1
1
1
6
0
1
1
1
7
0
0
0 or deleted
1
8
0
0
0 or deleted
1
9
0
0
0 or deleted
1
10
0
0
0 or deleted
1
11
1
1
2
1
12
0
1
2
1
13
0
1
2
1
14
0
0
0 or deleted
1
15
0
0
0 or deleted
1
16
0
0
0 or deleted
1
17
0
0
0 or deleted
1
18
0
0
0 or deleted
2
1
1
1
1
2
2
0
1
1
2
3
0
1
1
2
4
1
1
1
2
5
0
1
1
2
6
0
0
0 or delete
2
7
0
0
0 or delete
2
8
1
1
2
2
9
0
0
0 or delete
2
10
0
0
0 or delete
2
11
0
0
0 or delete
;
data want;
set have;
by subject_id;
if first.subject_id then group=0;
if high_cost=1 and (lag(high_cost)=0 or first.subject_id) then group+1;
want=ifn(high_cost=1,group,0);
drop group;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.