BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Aryyyan
Obsidian | Level 7

Hi all @Ksharp ,

 

I want to create variable episode (symptoms episode).

Criteria to create episode are

1) first episode = start with first symptom day and end when there is a gap of 2 or more days but minimum of 15 days

2) second episode = first symptom after first episode (has to be gap of 2 or more days and after minimum of 15 days since first day of first episode

3) create as many episode there is using criteria of second episode

 

ADT

SUBJID

PARAM

F_SYMPDT

SYMPDAY

EPISODE

29-Sep-20

VAC31518COV3001-3000107

MUSCLE ACHES PAINS

29-Sep-20

0

1

29-Sep-20

VAC31518COV3001-3000107

SHAKING CHILLS

29-Sep-20

0

1

29-Sep-20

VAC31518COV3001-3000107

SHAKING CHILLS

29-Sep-20

0

1

8-Oct-20

VAC31518COV3001-3000107

GISYMP

29-Sep-20

9

1

2-Dec-20

VAC31518COV3001-3000107

GISYMP

29-Sep-20

64

2

2-Dec-20

VAC31518COV3001-3000107

MALAISE

29-Sep-20

64

2

2-Dec-20

VAC31518COV3001-3000107

MALAISE

29-Sep-20

64

2

2-Dec-20

VAC31518COV3001-3000107

MALAISE

29-Sep-20

64

2

2-Dec-20

VAC31518COV3001-3000107

MUSCLE ACHES PAINS

29-Sep-20

64

2

2-Dec-20

VAC31518COV3001-3000107

SHAKING CHILLS

29-Sep-20

64

2

2-Dec-20

VAC31518COV3001-3000107

SHAKING CHILLS

29-Sep-20

64

2

24-Dec-20

VAC31518COV3001-3000107

FEVER

29-Sep-20

86

3

24-Dec-20

VAC31518COV3001-3000107

GISYMP

29-Sep-20

86

3

24-Dec-20

VAC31518COV3001-3000107

HEADACHE

29-Sep-20

86

3

24-Dec-20

VAC31518COV3001-3000107

MALAISE

29-Sep-20

86

3

24-Dec-20

VAC31518COV3001-3000107

MALAISE

29-Sep-20

86

3

24-Dec-20

VAC31518COV3001-3000107

MALAISE

29-Sep-20

86

3

24-Dec-20

VAC31518COV3001-3000107

MALAISE

29-Sep-20

86

3

24-Dec-20

VAC31518COV3001-3000107

MUSCLE ACHES PAINS

29-Sep-20

86

3

24-Dec-20

VAC31518COV3001-3000107

SHAKING CHILLS

29-Sep-20

86

3

25-Dec-20

VAC31518COV3001-3000107

FEVER

29-Sep-20

87

3

25-Dec-20

VAC31518COV3001-3000107

GISYMP

29-Sep-20

87

3

25-Dec-20

VAC31518COV3001-3000107

HEADACHE

29-Sep-20

87

3

25-Dec-20

VAC31518COV3001-3000107

MALAISE

29-Sep-20

87

3

25-Dec-20

VAC31518COV3001-3000107

MALAISE

29-Sep-20

87

3

25-Dec-20

VAC31518COV3001-3000107

MALAISE

29-Sep-20

87

3

25-Dec-20

VAC31518COV3001-3000107

MUSCLE ACHES PAINS

29-Sep-20

87

3

26-Dec-20

VAC31518COV3001-3000107

GISYMP

29-Sep-20

88

3

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

OK. Add one more line:

 



data want;
 set have;
 by id;
 retain first dif_days;

 gap=dif(SYMPDAY);

 dif_days=SYMPDAY-first;
 if first.id then EPISODE=0;   /*<--------*/
 if first.id or (gap>2 and dif_days>15) then do;first=SYMPDAY;EPISODE+1;end;
 keep id SYMPDAY EPISODE;
run;

View solution in original post

6 REPLIES 6
ballardw
Super User

I think that you may want to point out observations/work through a couple examples of exactly what this means:

1) first episode = start with first symptom day and end when there is a gap of 2 or more days but minimum of 15 days

Do you actually already have values for those variables Sympday and Episode? If not you need to point that out that you actually need help calculating Sympday (and maybe a few more rules about how)

 

If the minimum is 15 then exactly where does the 2 days actually come into play. Doesn't make much sense to me on the surface why the "2 or more" is included.

 

Is this supposed to per value of Param? Not at all mentioned why Param is included.

 

You should include something that is "not an episode" as well.

Aryyyan
Obsidian | Level 7
I think that you may want to point out observations/work through a couple examples of exactly what this means:
1) first episode = start with first symptom day and end when there is a gap of 2 or more days but minimum of 15 days
• This is a symptom dataset so first episode starts when SYMPDAY = 0 for all subjid and it will continue for 15 days doesn’t matter if what’s a gap. If we have symptoms on sympday 0, 1,2,3,5,8,10,12,13,15,16,17,20 then the first episode will be until SYMPDAY 17 and the second episode will start on SYMPDAY 20. The second episode will be for at least 15 days (20+15=35) regardless of the gap. So, if we have symptoms on day 35,36,37,44 then the second episode will be until day 37 and the third episode will start on day 44.
Do you actually already have values for those variables Sympday and Episode? If not you need to point that out that you actually need help calculating Sympday (and maybe a few more rules about how)
• Yes, I have valued for SYMPDAY but not EPISODE.
If the minimum is 15 then exactly where does the 2 days actually come into play. Doesn't make much sense to me on the surface why the "2 or more" is included.
• I explained this above.
Is this supposed to per value of Param? Not at all mentioned why Param is included.
• We can ignore param.
You should include something that is "not an episode" as well.
• All observations must have episodes because this dataset includes only observations with positive symptoms.
I hope this helps. Thank you!
Ksharp
Super User
/*
OK.Assuming I understood what you mean.
And SYMPDAY has been sorted by ascending.
*/
data have1;
retain id 1;
infile cards dsd;
input SYMPDAY @@;
cards;
0,1,2,3,5,8,10,12,13,15,16,17,20,35,36,37,44 
;
data have2;
retain id 2;
infile cards dsd;
input SYMPDAY @@;
cards;
0,1,2,3,5,8,10,12,13,15,16,17,20,35,36,37,44 
;
data have;
 set have1 have2;
run;


data want;
 set have;
 by id;
 retain first dif_days;

 gap=dif(SYMPDAY);

 dif_days=SYMPDAY-first;
 if first.id or (gap>2 and dif_days>15) then do;first=SYMPDAY;EPISODE+1;end;
 keep id SYMPDAY EPISODE;
run;
Aryyyan
Obsidian | Level 7
Thank you! Ya, that's what I was looking for with one minor change. When ID changes, the episode should reset to 1 instead of 4.
Ksharp
Super User

OK. Add one more line:

 



data want;
 set have;
 by id;
 retain first dif_days;

 gap=dif(SYMPDAY);

 dif_days=SYMPDAY-first;
 if first.id then EPISODE=0;   /*<--------*/
 if first.id or (gap>2 and dif_days>15) then do;first=SYMPDAY;EPISODE+1;end;
 keep id SYMPDAY EPISODE;
run;
Aryyyan
Obsidian | Level 7
Thank you so much for your help!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 6 replies
  • 831 views
  • 3 likes
  • 3 in conversation