BookmarkSubscribeRSS Feed
manya92
Fluorite | Level 6

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. 

1 REPLY 1
Reeza
Super User

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. 

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 534 views
  • 0 likes
  • 2 in conversation