Thanks in advance.
I have the data that contains patienid, drugname, drugstartdate, drugenddate. Same patient can have multiple drugs and even within same drug there can be multiple drugstartdate and drugenddates.
data have;
input ID DRUG $ START_DT :mmddyy. END_DT :mmddyy.;
datalines;
1 A 2/17/10 3/19/10
1 A 7/6/10 8/5/10
1 C 7/9/11 9/7/11
1 E 3/1/10 5/30/10
2 B 4/1/12 5/31/12
2 A 7/1/10 7/31/10
2 C 8/3/10 11/1/10
2 D 11/1/13 1/30/14
2 E 12/5/13 3/5/14
2 A 2/1/11 5/2/11
2 F 12/16/13 1/14/14
;
I want to create treatment episode for each patient, where the concomitant meds (taking different meds at the same time) are identified. Also the gaps have a row created with drug name as blank. So, for Id A, my new dataset should be like this:
Id druglist streat
1
1
1
1
1 A 07/06/10 08/5/10
1 blank 08/6/10
1 C 07/9/11
A similar problem was addessed last August
The same approach (an array with one element per day) could be used here.
Ok, so I modified your code and almost got what I wanted. Except that i cannot have extra rows for blank periods. Can anybody help in that. Below is the code I used.
data expand;
set sa.sample1_step1;
do date = stdt to enddt;
output;
end;
format date yymmdd10.;
keep ptid date drug;
run;
proc sql;
create table sumDoses as
select ptid, date, drug
from expand
group by ptid, date
order by ptid, date;
quit;
proc sort data = sumdoses;
by ptid date drug;
run;
proc transpose data = sumdoses out = trans;
by ptid date;
var drug;
run;
data trans1;
set trans;
drug = catx('+', col1, col2, col3);
keep ptid date drug ;
run;
data want;
set trans1;
by ptid drug notsorted;
retain date_start;
if first.drug then date_start = date;
if last.drug then do;
date_stop = date;
output;
end;
format date_start date_stop yymmdd10.;
keep ptid drug date_start date_stop;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.