BookmarkSubscribeRSS Feed
Carmine_Rossi
Calcite | Level 5

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

1 REPLY 1
Ksharp
Super User
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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 488 views
  • 0 likes
  • 2 in conversation