For next time:
What have you tried so far? By showing us some of your code even if not fully working we can better understand where you are coming from and better provide suitable answers.
Please also provide sample data ready made via SAS data step/datalines code as done below for data have so the ones helping you don't need to first spend time preparing sample data.
data have;
infile datalines truncover dsd;
input ID Line_of_treatment:$2. regimen $40.;
datalines;
1,1L,Radiation
1,2L,Radiation
1,3L,Radiation
1,4L,No subsequent line
1,5L,No subsequent line
1,6L,No subsequent line
2,1L,Radiation
2,2L,RCHOP/CHOP-based
2,3L,Chemo monotherapy
2,4L,No subsequent line
2,5L,No subsequent line
2,6L,No subsequent line
3,1L,radiation
3,2L,Radiation
3,3L,Radiation
3,4L,No subsequent line
3,5L,No subsequent line
3,6L,No subsequent line
4,1L,Radiation
4,2L,Other chemotherapy
4,3L,No subsequent line
4,4L,No subsequent line
4,5L,No subsequent line
4,6L,No subsequent line
5,1L,Radiation
5,2L,BR-based
5,3L,Radiation
5,1L,targeted
5,2L,Other chemotherapy
5,3L,targeted
5,4L,Radiation
5,5L,Radiation
5,6L,Radiation
;
proc sort data=have out=inter;
by id Line_of_treatment;
run;
data want(keep=id cohort_flg_:);
set inter;
by id Line_of_treatment;
retain radiation_cnt other_treatment_cnt cohort_flg_1 cohort_flg_2;
if upcase(regimen) ne 'NO SUBSEQUENT LINE' then
do;
if upcase(regimen)='RADIATION' then
do;
radiation_cnt+1;
if other_treatment_cnt>1 then cohort_flg_2=1;
end;
else
do;
other_treatment_cnt+1;
if radiation_cnt>0 then cohort_flg_1=1;
end;
end;
if last.id then
do;
output;
call missing(radiation_cnt, other_treatment_cnt, cohort_flg_1, cohort_flg_2);
end;
run;
proc print data=want;
run;
... View more