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

I need help to calculate these 2 flags value.

 

Flag1 = first day of 3 consecutive days with observed severity “None”. A “Missing” grade in the middle of “None” grades disrupts the sequence and the count starts over at the next “None”. If never any symptoms on-study, or never 3 consecutive days with “None” after a grade > 0, set to 998.

 

Flag2 = If a symptom was reported with grade > “None”, set to last day a symptom was reported before 3 consecutive “None” days. If no symptom before end of diary, set to "No value".

 

SUBJECTcovdaySYCDSYSEVFlag1Flag2
7153079780ABDNone  
7153079781ABDNone  
7153079782ABDNone  
7153079783ABDMild Y
7153079784ABDNoneY 
7153079785ABDNone  
7153079786ABDNone  
7153079787ABDNone  
7153079788ABDNone  
7153079789ABDNone  
7153079780ANOSMIANone  
7153079781ANOSMIANone  
7153079782ANOSMIANone  
7153079783ANOSMIANone  
7153079784ANOSMIAMild Y
7153079785ANOSMIANoneY 
7153079786ANOSMIANone  
7153079787ANOSMIANone  
7153079788ANOSMIANone  
7153079789ANOSMIANone  
7153079780SOBNone  
7153079781SOBNone  
7153079782SOBNone  
7153079783SOBNone  
7153079784SOBNone  
7153079785SOBNone  
7153079786SOBNone  
7153079787SOBNone  
7153079788SOBNone  
7153079789SOBNone  
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

OK . You want this ?

 

 

data have;
  infile datalines4
    dlm='|'
    truncover
    dsd;
  input
    subject          : $9.
    covday           : best32.
    sycd             : $7.
    sysev            : $4.
    flag1            : $1.
    flag2            : $1.;
  datalines4;
715307978|0|ABD|None| | 
715307978|1|ABD|None| | 
715307978|2|ABD|None| | 
715307978|3|ABD|Mild| |Y
715307978|4|ABD|None|Y| 
715307978|5|ABD|None| | 
715307978|6|ABD|None| | 
715307978|7|ABD|None| | 
715307978|8|ABD|None| | 
715307978|9|ABD|None| | 
715307978|0|ANOSMIA|None| | 
715307978|1|ANOSMIA|None| | 
715307978|2|ANOSMIA|None| | 
715307978|3|ANOSMIA|None| | 
715307978|4|ANOSMIA|Mild| |Y
715307978|5|ANOSMIA|None|Y| 
715307978|6|ANOSMIA|None| | 
715307978|7|ANOSMIA|None| | 
715307978|8|ANOSMIA|None| | 
715307978|9|ANOSMIA|None| | 
715307978|10|ANOSMIA|Mild| |Y
715307978|11|ANOSMIA|None|Y| 
715307978|12|ANOSMIA|None| | 
715307978|13|ANOSMIA|None| | 
715307978|0|SOB|None| | 
715307978|1|SOB|None| | 
715307978|2|SOB|None| | 
715307978|3|SOB|None| | 
715307978|4|SOB|None| | 
715307978|5|SOB|None| | 
715307978|6|SOB|None| | 
715307978|7|SOB|None| | 
715307978|8|SOB|None| | 
715307978|9|SOB|None| | 
;;;;


data _have;
n=0;
do  until(last.sysev);
 set have;
 by subject sycd sysev  notsorted;
 n+1;
 if last.sycd then last_group=1;
end;
do until(last.sysev);
 set have;
 by  subject sycd sysev notsorted;
 output;
end;
run;


data want;
 merge _have _have(keep=subject sycd sysev n last_group
 rename=(subject=_s sycd=_c sysev=_sev n=_n last_group=_last_group) firstobs=2);
 if subject=lag(subject) and sysev='None' and lag(sysev) ne 'None' and n>2 and last_group then new_flag1='Y';
 if subject=_s and sycd=_c and _sev='None' and sysev ne 'None'  and _n>2 and _last_group  then new_flag2='Y';
drop _: n last_group;
run;

View solution in original post

11 REPLIES 11
Patrick
Opal | Level 21

Please provide sample data that covers all the cases you describe. This will help to avoid misunderstandings.

 

Flag1 = first day of 3 consecutive days with observed severity “None”. A “Missing” grade in the middle of “None” grades disrupts the sequence and the count starts over at the next “None”. If never any symptoms on-study, or never 3 consecutive days with “None” after a grade > 0, set to 998.

 

Please also provide sample data as a working SAS data step as done below for the data you already posted.

data have;
  infile datalines4
    dlm='|'
    truncover
    dsd;
  input
    subject          : $9.
    covday           : best32.
    sycd             : $7.
    sysev            : $4.
    flag1            : $1.
    flag2            : $1.;
  datalines4;
715307978|0|ABD|None| | 
715307978|1|ABD|None| | 
715307978|2|ABD|None| | 
715307978|3|ABD|Mild| |Y
715307978|4|ABD|None|Y| 
715307978|5|ABD|None| | 
715307978|6|ABD|None| | 
715307978|7|ABD|None| | 
715307978|8|ABD|None| | 
715307978|9|ABD|None| | 
715307978|0|ANOSMIA|None| | 
715307978|1|ANOSMIA|None| | 
715307978|2|ANOSMIA|None| | 
715307978|3|ANOSMIA|None| | 
715307978|4|ANOSMIA|Mild| |Y
715307978|5|ANOSMIA|None|Y| 
715307978|6|ANOSMIA|None| | 
715307978|7|ANOSMIA|None| | 
715307978|8|ANOSMIA|None| | 
715307978|9|ANOSMIA|None| | 
715307978|0|SOB|None| | 
715307978|1|SOB|None| | 
715307978|2|SOB|None| | 
715307978|3|SOB|None| | 
715307978|4|SOB|None| | 
715307978|5|SOB|None| | 
715307978|6|SOB|None| | 
715307978|7|SOB|None| | 
715307978|8|SOB|None| | 
715307978|9|SOB|None| | 
;;;;
Reeza
Super User
Do you always have only 9 days? If so, this may be one of the few cases where a wide format would be easier to work with.
Reeza
Super User
Also your criteria in the post doesn't match what's in the subject line....which one is it? Assuming subject line as it matches the data more?
Aryyyan
Obsidian | Level 7

Thank you @Patrick and @Reeza.

 

In datset below, I need one observation per subject*symptom where

R_T1 = first day of 3 consecutive days with observed severity “None”. A “Missing” grade in the middle of “None” grades disrupts the sequence and the count starts over at the next “None”. If never any symptoms on-study, or never 3 consecutive days with “None” after a grade > 0, set to 998.

For example below, for sycd ABD, I need covday 15 as R_T1,  for sycd ANOSMIA covday 17, for COUGH covday 17, and for SOB since there is never 3 consecutive none after Severe so I need value 998.

 

R_T0 = If a symptom was reported with grade > “None”, set to last day a symptom was reported in [0, R_T1] before 3 consecutive “None” days. If no symptom before end of diary, set to 998.

For example below, for sycd ABD, I need covday 14 as R_T1,  for sycd ANOSMIA covday 15, for COUGH covday 18, and for SOB since there is never 3 consecutive none after Severe so I need value 998.

 

data have;

  infile datalines4

    dlm='|'

    truncover

    dsd;

  input

  subject          : $9.

    covday           : best32.

    sycd             : $7.

    sysev            : $8.

    sysevn                                            : 1.;

  datalines4;

775575874|0|ABD|None|0

775575874|1|ABD|None|0

775575874|2|ABD|None|0

775575874|3|ABD|None|0

775575874|4|ABD|None|0

775575874|5|ABD|None|0

775575874|6|ABD|None|0

775575874|7|ABD|None|0

775575874|8|ABD|None|0

775575874|9|ABD|None|0

775575874|10|ABD|None|0

775575874|11|ABD|None|0

775575874|12|ABD|None|0

775575874|13|ABD|None|0

775575874|14|ABD|Mild|1

775575874|15|ABD|None|0

775575874|16|ABD|None|0

775575874|17|ABD|None|0

775575874|18|ABD|None|0

775575874|19|ABD|None|0      

775575874|20|ABD|None|0

775575874|0|ANOSMIA|None|0

775575874|1|ANOSMIA|None|0

775575874|2|ANOSMIA|None|0

775575874|3|ANOSMIA|None|0

775575874|4|ANOSMIA|None|0

775575874|5|ANOSMIA|None|0

775575874|6|ANOSMIA|None|0

775575874|7|ANOSMIA| |.

775575874|8|ANOSMIA|None|0

775575874|9|ANOSMIA|None|0

775575874|10|ANOSMIA|None|0

775575874|11|ANOSMIA|None|0

775575874|12|ANOSMIA|None|0

775575874|13|ANOSMIA|None|0

775575874|14|ANOSMIA| |.

775575874|15|ANOSMIA|Mild|1

775575874|16|ANOSMIA| |.

775575874|17|ANOSMIA|None|0

775575874|18|ANOSMIA|None|0

775575874|19|ANOSMIA|None|0

775575874|20|ANOSMIA|None|0

775575874|0|COUGH|None|0

775575874|1|COUGH|None|0

775575874|2|COUGH|None|0

775575874|3|COUGH|None|0

775575874|4|COUGH|None|0

775575874|5|COUGH|None|0

775575874|6|COUGH|None|0

775575874|7|COUGH|None|0

775575874|8|COUGH|None|0

775575874|9|COUGH|Mild|1

775575874|10|COUGH|Mild|1

775575874|11|COUGH|Mild|1

775575874|12|COUGH|Mild|1

775575874|13|COUGH|Mild|1

775575874|14|COUGH| |.

775575874|15|COUGH|Moderate|2

775575874|16|COUGH| |.

775575874|17|COUGH|Severe|3

775575874|18|COUGH|None|0

775575874|19|COUGH|None|0

775575874|20|COUGH|None|0

775575874|0|SOB|None|0

775575874|1|SOB|None|0

775575874|2|SOB|None|0

775575874|3|SOB|None|0

775575874|4|SOB|None|0

775575874|5|SOB|None|0

775575874|6|SOB|None|0

775575874|7|SOB|None|0

775575874|8|SOB|None|0

775575874|9|SOB|None|0

775575874|10|SOB|Mild|1

775575874|11|SOB|None|0

775575874|12|SOB|Mild|1

775575874|13|SOB|Mild|1

775575874|14|SOB| |.

775575874|15|SOB|Moderate|2

775575874|16|SOB| |.

775575874|17|SOB| |.

775575874|18|SOB|Moderate|2

775575874|19|SOB| |.

775575874|20|SOB|Severe|3

;;;;

 data have;
infile datalines4
dlm='|'
truncover
dsd;
input
subject : $9.
covday : best32.
sycd : $7.
sysev : $8.
sysevn : 1.;
datalines4;
775575874|0|ABD|None|0
775575874|1|ABD|None|0
775575874|2|ABD|None|0
775575874|3|ABD|None|0
775575874|4|ABD|None|0
775575874|5|ABD|None|0
775575874|6|ABD|None|0
775575874|7|ABD|None|0
775575874|8|ABD|None|0
775575874|9|ABD|None|0
775575874|10|ABD|None|0
775575874|11|ABD|None|0
775575874|12|ABD|None|0
775575874|13|ABD|None|0
775575874|14|ABD|Mild|1
775575874|15|ABD|None|0
775575874|16|ABD|None|0
775575874|17|ABD|None|0
775575874|18|ABD|None|0
775575874|19|ABD|None|0
775575874|20|ABD|None|0
775575874|0|ANOSMIA|None|0
775575874|1|ANOSMIA|None|0
775575874|2|ANOSMIA|None|0
775575874|3|ANOSMIA|None|0
775575874|4|ANOSMIA|None|0
775575874|5|ANOSMIA|None|0
775575874|6|ANOSMIA|None|0
775575874|7|ANOSMIA| |.
775575874|8|ANOSMIA|None|0
775575874|9|ANOSMIA|None|0
775575874|10|ANOSMIA|None|0
775575874|11|ANOSMIA|None|0
775575874|12|ANOSMIA|None|0
775575874|13|ANOSMIA|None|0
775575874|14|ANOSMIA| |.
775575874|15|ANOSMIA|Mild|1
775575874|16|ANOSMIA| |.
775575874|17|ANOSMIA|None|0
775575874|18|ANOSMIA|None|0
775575874|19|ANOSMIA|None|0
775575874|20|ANOSMIA|None|0
775575874|0|COUGH|None|0
775575874|1|COUGH|None|0
775575874|2|COUGH|None|0
775575874|3|COUGH|None|0
775575874|4|COUGH|None|0
775575874|5|COUGH|None|0
775575874|6|COUGH|None|0
775575874|7|COUGH|None|0
775575874|8|COUGH|None|0
775575874|9|COUGH|Mild|1
775575874|10|COUGH|Mild|1
775575874|11|COUGH|Mild|1
775575874|12|COUGH|Mild|1
775575874|13|COUGH|Mild|1
775575874|14|COUGH| |.
775575874|15|COUGH|Moderate|2
775575874|16|COUGH| |.
775575874|17|COUGH|Severe|3
775575874|18|COUGH|None|0
775575874|19|COUGH|None|0
775575874|20|COUGH|None|0
775575874|0|SOB|None|0
775575874|1|SOB|None|0
775575874|2|SOB|None|0
775575874|3|SOB|None|0
775575874|4|SOB|None|0
775575874|5|SOB|None|0
775575874|6|SOB|None|0
775575874|7|SOB|None|0
775575874|8|SOB|None|0
775575874|9|SOB|None|0
775575874|10|SOB|Mild|1
775575874|11|SOB|None|0
775575874|12|SOB|Mild|1
775575874|13|SOB|Mild|1
775575874|14|SOB| |.
775575874|15|SOB|Moderate|2
775575874|16|SOB| |.
775575874|17|SOB| |.
775575874|18|SOB|Moderate|2
775575874|19|SOB| |.
775575874|20|SOB|Severe|3
;;;;


 

 data have;
infile datalines4
dlm='|'
truncover
dsd;
input
subject : $9.
covday : best32.
sycd : $7.
sysev : $8.
sysevn : 1.;
datalines4;
775575874|0|ABD|None|0
775575874|1|ABD|None|0
775575874|2|ABD|None|0
775575874|3|ABD|None|0
775575874|4|ABD|None|0
775575874|5|ABD|None|0
775575874|6|ABD|None|0
775575874|7|ABD|None|0
775575874|8|ABD|None|0
775575874|9|ABD|None|0
775575874|10|ABD|None|0
775575874|11|ABD|None|0
775575874|12|ABD|None|0
775575874|13|ABD|None|0
775575874|14|ABD|Mild|1
775575874|15|ABD|None|0
775575874|16|ABD|None|0
775575874|17|ABD|None|0
775575874|18|ABD|None|0
775575874|19|ABD|None|0
775575874|20|ABD|None|0
775575874|0|ANOSMIA|None|0
775575874|1|ANOSMIA|None|0
775575874|2|ANOSMIA|None|0
775575874|3|ANOSMIA|None|0
775575874|4|ANOSMIA|None|0
775575874|5|ANOSMIA|None|0
775575874|6|ANOSMIA|None|0
775575874|7|ANOSMIA| |.
775575874|8|ANOSMIA|None|0
775575874|9|ANOSMIA|None|0
775575874|10|ANOSMIA|None|0
775575874|11|ANOSMIA|None|0
775575874|12|ANOSMIA|None|0
775575874|13|ANOSMIA|None|0
775575874|14|ANOSMIA| |.
775575874|15|ANOSMIA|Mild|1
775575874|16|ANOSMIA| |.
775575874|17|ANOSMIA|None|0
775575874|18|ANOSMIA|None|0
775575874|19|ANOSMIA|None|0
775575874|20|ANOSMIA|None|0
775575874|0|COUGH|None|0
775575874|1|COUGH|None|0
775575874|2|COUGH|None|0
775575874|3|COUGH|None|0
775575874|4|COUGH|None|0
775575874|5|COUGH|None|0
775575874|6|COUGH|None|0
775575874|7|COUGH|None|0
775575874|8|COUGH|None|0
775575874|9|COUGH|Mild|1
775575874|10|COUGH|Mild|1
775575874|11|COUGH|Mild|1
775575874|12|COUGH|Mild|1
775575874|13|COUGH|Mild|1
775575874|14|COUGH| |.
775575874|15|COUGH|Moderate|2
775575874|16|COUGH| |.
775575874|17|COUGH|Severe|3
775575874|18|COUGH|None|0
775575874|19|COUGH|None|0
775575874|20|COUGH|None|0
775575874|0|SOB|None|0
775575874|1|SOB|None|0
775575874|2|SOB|None|0
775575874|3|SOB|None|0
775575874|4|SOB|None|0
775575874|5|SOB|None|0
775575874|6|SOB|None|0
775575874|7|SOB|None|0
775575874|8|SOB|None|0
775575874|9|SOB|None|0
775575874|10|SOB|Mild|1
775575874|11|SOB|None|0
775575874|12|SOB|Mild|1
775575874|13|SOB|Mild|1
775575874|14|SOB| |.
775575874|15|SOB|Moderate|2
775575874|16|SOB| |.
775575874|17|SOB| |.
775575874|18|SOB|Moderate|2
775575874|19|SOB| |.
775575874|20|SOB|Severe|3
;;;;


 data have;
infile datalines4
dlm='|'
truncover
dsd;
input
subject : $9.
covday : best32.
sycd : $7.
sysev : $8.
sysevn : 1.;
datalines4;
775575874|0|ABD|None|0
775575874|1|ABD|None|0
775575874|2|ABD|None|0
775575874|3|ABD|None|0
775575874|4|ABD|None|0
775575874|5|ABD|None|0
775575874|6|ABD|None|0
775575874|7|ABD|None|0
775575874|8|ABD|None|0
775575874|9|ABD|None|0
775575874|10|ABD|None|0
775575874|11|ABD|None|0
775575874|12|ABD|None|0
775575874|13|ABD|None|0
775575874|14|ABD|Mild|1
775575874|15|ABD|None|0
775575874|16|ABD|None|0
775575874|17|ABD|None|0
775575874|18|ABD|None|0
775575874|19|ABD|None|0
775575874|20|ABD|None|0
775575874|0|ANOSMIA|None|0
775575874|1|ANOSMIA|None|0
775575874|2|ANOSMIA|None|0
775575874|3|ANOSMIA|None|0
775575874|4|ANOSMIA|None|0
775575874|5|ANOSMIA|None|0
775575874|6|ANOSMIA|None|0
775575874|7|ANOSMIA| |.
775575874|8|ANOSMIA|None|0
775575874|9|ANOSMIA|None|0
775575874|10|ANOSMIA|None|0
775575874|11|ANOSMIA|None|0
775575874|12|ANOSMIA|None|0
775575874|13|ANOSMIA|None|0
775575874|14|ANOSMIA| |.
775575874|15|ANOSMIA|Mild|1
775575874|16|ANOSMIA| |.
775575874|17|ANOSMIA|None|0
775575874|18|ANOSMIA|None|0
775575874|19|ANOSMIA|None|0
775575874|20|ANOSMIA|None|0
775575874|0|COUGH|None|0
775575874|1|COUGH|None|0
775575874|2|COUGH|None|0
775575874|3|COUGH|None|0
775575874|4|COUGH|None|0
775575874|5|COUGH|None|0
775575874|6|COUGH|None|0
775575874|7|COUGH|None|0
775575874|8|COUGH|None|0
775575874|9|COUGH|Mild|1
775575874|10|COUGH|Mild|1
775575874|11|COUGH|Mild|1
775575874|12|COUGH|Mild|1
775575874|13|COUGH|Mild|1
775575874|14|COUGH| |.
775575874|15|COUGH|Moderate|2
775575874|16|COUGH| |.
775575874|17|COUGH|Severe|3
775575874|18|COUGH|None|0
775575874|19|COUGH|None|0
775575874|20|COUGH|None|0
775575874|0|SOB|None|0
775575874|1|SOB|None|0
775575874|2|SOB|None|0
775575874|3|SOB|None|0
775575874|4|SOB|None|0
775575874|5|SOB|None|0
775575874|6|SOB|None|0
775575874|7|SOB|None|0
775575874|8|SOB|None|0
775575874|9|SOB|None|0
775575874|10|SOB|Mild|1
775575874|11|SOB|None|0
775575874|12|SOB|Mild|1
775575874|13|SOB|Mild|1
775575874|14|SOB| |.
775575874|15|SOB|Moderate|2
775575874|16|SOB| |.
775575874|17|SOB| |.
775575874|18|SOB|Moderate|2
775575874|19|SOB| |.
775575874|20|SOB|Severe|3
;;;;


 

Ksharp
Super User

Assuming I understand your question.

 

 

data have;
  infile datalines4
    dlm='|'
    truncover
    dsd;
  input
    subject          : $9.
    covday           : best32.
    sycd             : $7.
    sysev            : $4.
    flag1            : $1.
    flag2            : $1.;
  datalines4;
715307978|0|ABD|None| | 
715307978|1|ABD|None| | 
715307978|2|ABD|None| | 
715307978|3|ABD|Mild| |Y
715307978|4|ABD|None|Y| 
715307978|5|ABD|None| | 
715307978|6|ABD|None| | 
715307978|7|ABD|None| | 
715307978|8|ABD|None| | 
715307978|9|ABD|None| | 
715307978|0|ANOSMIA|None| | 
715307978|1|ANOSMIA|None| | 
715307978|2|ANOSMIA|None| | 
715307978|3|ANOSMIA|None| | 
715307978|4|ANOSMIA|Mild| |Y
715307978|5|ANOSMIA|None|Y| 
715307978|6|ANOSMIA|None| | 
715307978|7|ANOSMIA|None| | 
715307978|8|ANOSMIA|None| | 
715307978|9|ANOSMIA|None| | 
715307978|0|SOB|None| | 
715307978|1|SOB|None| | 
715307978|2|SOB|None| | 
715307978|3|SOB|None| | 
715307978|4|SOB|None| | 
715307978|5|SOB|None| | 
715307978|6|SOB|None| | 
715307978|7|SOB|None| | 
715307978|8|SOB|None| | 
715307978|9|SOB|None| | 
;;;;



data want;
 merge have have(keep=subject sycd sysev rename=(subject=_s sycd=_c sysev=_sev) firstobs=2);
 if subject=lag(subject) and sysev='None' and lag(sysev) ne 'None' then new_flag1='Y';
 if subject=_s and sycd=_c and _sev='None' and sysev ne 'None' then new_flag2='Y';
drop _:;
run;
Aryyyan
Obsidian | Level 7

Hi @Ksharp , 

 

I need one observation per subject*symptom where

R_T1 (Flag1) = first day of 3 consecutive days with observed severity “None”. A “Missing” grade in the middle of “None” grades disrupts the sequence and the count starts over at the next “None”. If never any symptoms on-study, or never 3 consecutive days with “None” after a grade > 0, set to 998.

For example below, for sycd ABD, I need covday 15 as R_T1,  for sycd ANOSMIA covday 17, for COUGH covday 17, and for SOB since there is never 3 consecutive none after Severe so I need value 998.

 

R_T0 (Flag2)= If a symptom was reported with grade > “None”, set to last day a symptom was reported in [0, R_T1] before 3 consecutive “None” days. If no symptom before end of diary, set to 998.

For example below, for sycd ABD, I need covday 14 as R_T1,  for sycd ANOSMIA covday 15, for COUGH covday 18, and for SOB since there is never 3 consecutive none after Severe so I need value 998.

 

Please check new dataset above that I posted. 

 

Thank you for your help. 

Ksharp
Super User

OK. My bad. You want "3 consecutive days with observed severity “None”. " . Try this :

 

data have;
  infile datalines4
    dlm='|'
    truncover
    dsd;
  input
    subject          : $9.
    covday           : best32.
    sycd             : $7.
    sysev            : $4.
    flag1            : $1.
    flag2            : $1.;
  datalines4;
715307978|0|ABD|None| | 
715307978|1|ABD|None| | 
715307978|2|ABD|None| | 
715307978|3|ABD|Mild| |Y
715307978|4|ABD|None|Y| 
715307978|5|ABD|None| | 
715307978|6|ABD|None| | 
715307978|7|ABD|None| | 
715307978|8|ABD|None| | 
715307978|9|ABD|None| | 
715307978|0|ANOSMIA|None| | 
715307978|1|ANOSMIA|None| | 
715307978|2|ANOSMIA|None| | 
715307978|3|ANOSMIA|None| | 
715307978|4|ANOSMIA|Mild| |Y
715307978|5|ANOSMIA|None|Y| 
715307978|6|ANOSMIA|None| | 
715307978|7|ANOSMIA|None| | 
715307978|8|ANOSMIA|None| | 
715307978|9|ANOSMIA|None| | 
715307978|0|SOB|None| | 
715307978|1|SOB|None| | 
715307978|2|SOB|None| | 
715307978|3|SOB|None| | 
715307978|4|SOB|None| | 
715307978|5|SOB|None| | 
715307978|6|SOB|None| | 
715307978|7|SOB|None| | 
715307978|8|SOB|None| | 
715307978|9|SOB|None| | 
;;;;


data _have;
n=0;
do  until(last.sysev);
 set have;
 by subject sycd sysev  notsorted;
 n+1;
end;
do until(last.sysev);
 set have;
 by  subject sycd sysev notsorted;
 output;
end;
run;


data want;
 merge _have _have(keep=subject sycd sysev n rename=(subject=_s sycd=_c sysev=_sev n=_n) firstobs=2);
 if subject=lag(subject) and sysev='None' and lag(sysev) ne 'None' and n>3 then new_flag1='Y';
 if subject=_s and sycd=_c and _sev='None' and sysev ne 'None'  and _n>3 then new_flag2='Y';
drop _: n;
run;
Aryyyan
Obsidian | Level 7

Thank you @Ksharp. It is very helpful but I want  "3 consecutive days with observed severity “None” after "Last Not-None (Missing, Mild, Moderate, or Severe)" severity. 

Reeza
Super User

@Aryyyan wrote:

Thank you @Ksharp. It is very helpful but I want  "3 consecutive days with observed severity “None” after "Last Not-None (Missing, Mild, Moderate, or Severe)" severity. 


As I noted a few days ago, that criteria is in your subject line but you weren't including it in your actual requirements.

Ksharp
Super User

OK . You want this ?

 

 

data have;
  infile datalines4
    dlm='|'
    truncover
    dsd;
  input
    subject          : $9.
    covday           : best32.
    sycd             : $7.
    sysev            : $4.
    flag1            : $1.
    flag2            : $1.;
  datalines4;
715307978|0|ABD|None| | 
715307978|1|ABD|None| | 
715307978|2|ABD|None| | 
715307978|3|ABD|Mild| |Y
715307978|4|ABD|None|Y| 
715307978|5|ABD|None| | 
715307978|6|ABD|None| | 
715307978|7|ABD|None| | 
715307978|8|ABD|None| | 
715307978|9|ABD|None| | 
715307978|0|ANOSMIA|None| | 
715307978|1|ANOSMIA|None| | 
715307978|2|ANOSMIA|None| | 
715307978|3|ANOSMIA|None| | 
715307978|4|ANOSMIA|Mild| |Y
715307978|5|ANOSMIA|None|Y| 
715307978|6|ANOSMIA|None| | 
715307978|7|ANOSMIA|None| | 
715307978|8|ANOSMIA|None| | 
715307978|9|ANOSMIA|None| | 
715307978|10|ANOSMIA|Mild| |Y
715307978|11|ANOSMIA|None|Y| 
715307978|12|ANOSMIA|None| | 
715307978|13|ANOSMIA|None| | 
715307978|0|SOB|None| | 
715307978|1|SOB|None| | 
715307978|2|SOB|None| | 
715307978|3|SOB|None| | 
715307978|4|SOB|None| | 
715307978|5|SOB|None| | 
715307978|6|SOB|None| | 
715307978|7|SOB|None| | 
715307978|8|SOB|None| | 
715307978|9|SOB|None| | 
;;;;


data _have;
n=0;
do  until(last.sysev);
 set have;
 by subject sycd sysev  notsorted;
 n+1;
 if last.sycd then last_group=1;
end;
do until(last.sysev);
 set have;
 by  subject sycd sysev notsorted;
 output;
end;
run;


data want;
 merge _have _have(keep=subject sycd sysev n last_group
 rename=(subject=_s sycd=_c sysev=_sev n=_n last_group=_last_group) firstobs=2);
 if subject=lag(subject) and sysev='None' and lag(sysev) ne 'None' and n>2 and last_group then new_flag1='Y';
 if subject=_s and sycd=_c and _sev='None' and sysev ne 'None'  and _n>2 and _last_group  then new_flag2='Y';
drop _: n last_group;
run;
Aryyyan
Obsidian | Level 7
Yup, thank you so much for your help!!!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 11 replies
  • 1326 views
  • 4 likes
  • 4 in conversation