I have this code, but i need it to run a certain number of times using the do loop.
proc sql ;
create table _02_pt_regimen as
select distinct a.PatientID, a.last_visit, a.death_date, a.MetDiagnosisDate, a.Birthyear, a.age, a.VisitDate,b.StartDate , b.EndDate, b.LineName
from derived.pt_cohort as a
inner join dfi_panc.lineoftherapy as b
on a.PatientID = b.PatientID
where year(b.StartDate) in (2015,2016,2017) and (b.LineName in ('FOLFIRINOX', 'FOLFIRI')
order by PatientID, StartDate ;
quit ; /*3396*/
/*GETTING THE FIRST START DATE */
data _02_first_epi ;
set _02_pt_regimen ;
format episode1_start episode1_end mmddyy10. ;
by PatientID StartDate;
if first.PatientID ;
episode1_start= StartDate ;
episode1_end = min(death_date, episode1_start +180) ;
run ; /*2575*/
/*MERGING WITH THE TREATMENT LEVEL DATASET*/
proc sql ;
create table _02_second_epi as
select b.PatientID , a.episode1_start, a.episode1_end,b.StartDate, b.EndDate, b.LineName, a.death_date
from _02_first_epi as a
inner join _02_pt_regimen as b
on a.PatientID=b.PatientID
order by b.PatientID, b.StartDate;
quit ; /*5330*/
/* WHEN PATIENT STARTS THE SECOND EPISODE */
data _02_second_epi2;
set _02_second_epi ;
format episode2_start episode2_end mmddyy10. ;
by PatientID StartDate ;
episode2_start = episode1_end+1 ;
if (episode2_start le EndDate) then do ;
episode2_start =max(StartDate, episode2_start) ;
episode2_end= episode2_start +180 ;
output ;
end ;
run ;
/*NOW WE WANT TO ADD A DO LOOP THAT WILL CHANGE OUR EPISODE2_START = EPISODE1_END +1 EVERY TIME WE CALCULATE THE NEXT EPISODE,
FOR EG. EPISODE3_START = EPISODE2_END+1 AND SO ON */
proc sort data = _02_second_epi2 ;
by PatientID episode2_start ;
run ;
data _02_second_test ;
set _02_second_epi2 ;
by PatientID episode2_start ;
if first.PatientID ;
run ;
F002F4C07392F | 08/19/2015 | 02/15/2016 | 08/19/2015 | 04/05/2016 | FOLFIRINOX | 02/16/2016 | 08/14/2016 |
2 | F002F4C07392F | 08/19/2015 | 02/15/2016 | 04/06/2016 | 05/11/2016 | Gemcitabine,Paclitaxel Protein-Bound | 04/06/2016 | 10/03/2016 |
3 | F00314B361B6A | 11/28/2016 | 05/27/2017 | 11/28/2016 | 08/21/2017 | Gemcitabine,Paclitaxel Protein-Bound | 05/28/2017 | 11/24/2017 |
4 | F00314B361B6A | 11/28/2016 | 05/27/2017 | 08/22/2017 | 03/07/2018 | FOLFOX | 08/22/2017 | 02/18/2018 |
5 | F007499692F0D | 08/28/2017 | 02/24/2018 | 11/01/2017 | 03/26/2018 | Gemcitabine,Paclitaxel Protein-Bound | 02/25/2018 | 08/24/2018 |
6 | F00CC20661EE3 | 10/19/2015 | 04/16/2016 | 10/19/2015 | 05/03/2016 | Gemcitabine,Paclitaxel Protein-Bound | 04/17/2016 | 10/14/2016 |
7 | F00CC20661EE3 | 10/19/2015 | 04/16/2016 | 05/04/2016 | 05/09/2016 | FOLFIRINOX | 05/04/2016 | 10/31/2016 |
8 | F015E4ADD6564 | 10/11/2016 | 10/15/2016 | 10/11/2016 | 10/28/2016 | FOLFOX | 10/16/2016 | 04/14/2017 |
9 | F016977DDEFE8 | 05/04/2016 | 10/31/2016 | 09/21/2016 | 05/24/2017 | Gemcitabine,Paclitaxel Protein-Bound | 11/01/2016 | 04/30/2017 |
10 | F016AAE0393FF | 07/31/2015 | 12/15/2015 | 07/31/2015 | 12/22/2015 | Gemcitabine,Paclitaxel Protein-Bound | 12/16/2015 | 06/13/2016 |
Now i want it to show me for all episodes eg, episode 3 ,4 ,5 and so on until the very end that is EndDate reaches. I have to use a do loop but i am not sure how many iterations I would need for it.
Maybe you don't....can you post some more data with what you want as output. If you can post your data as a data step that helps a lot because then we don't have to spend time figuring out how to read your data.
Instructions can be found here:
PS. Please take some time to go through your previous questions and mark them as solved, if they are solved.
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!
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.