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!
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;
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.
/*
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;
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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.