DATA Step, Macro, Functions and more

treatment lines

Reply
Contributor
Posts: 29

treatment lines

[ Edited ]

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 ;

 

F002F4C07392F08/19/201502/15/201608/19/201504/05/2016FOLFIRINOX02/16/201608/14/2016
2F002F4C07392F08/19/201502/15/201604/06/201605/11/2016Gemcitabine,Paclitaxel Protein-Bound04/06/201610/03/2016
3F00314B361B6A11/28/201605/27/201711/28/201608/21/2017Gemcitabine,Paclitaxel Protein-Bound05/28/201711/24/2017
4F00314B361B6A11/28/201605/27/201708/22/201703/07/2018FOLFOX08/22/201702/18/2018
5F007499692F0D08/28/201702/24/201811/01/201703/26/2018Gemcitabine,Paclitaxel Protein-Bound02/25/201808/24/2018
6F00CC20661EE310/19/201504/16/201610/19/201505/03/2016Gemcitabine,Paclitaxel Protein-Bound04/17/201610/14/2016
7F00CC20661EE310/19/201504/16/201605/04/201605/09/2016FOLFIRINOX05/04/201610/31/2016
8F015E4ADD656410/11/201610/15/201610/11/201610/28/2016FOLFOX10/16/201604/14/2017
9F016977DDEFE805/04/201610/31/201609/21/201605/24/2017Gemcitabine,Paclitaxel Protein-Bound11/01/201604/30/2017
10F016AAE0393FF07/31/201512/15/201507/31/201512/22/2015Gemcitabine,Paclitaxel Protein-Bound12/16/201506/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. 

Super User
Posts: 23,262

Re: treatment lines

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:

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

PS. Please take some time to go through your previous questions and mark them as solved, if they are solved. 

 

 

Ask a Question
Discussion stats
  • 1 reply
  • 70 views
  • 0 likes
  • 2 in conversation