BookmarkSubscribeRSS Feed
devsas
Pyrite | Level 9

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                           endtreat

1                                  A                     02/17/10                      03/01/10

1                                  AE                   03/1/10                        03/19/10

1                                  E                      03/19/10                      05/30/10

1                                  blank               06/1/10                        07/5/10

1                            A                     07/06/10                           08/5/10

1                           blank                08/6/10                              07/8/11

1                           C                      07/9/11                              09/7/11

 

 

3 REPLIES 3
PGStats
Opal | Level 21

A similar problem was addessed last August

 

https://communities.sas.com/t5/SAS-Studio/Use-time-overlaps-to-update-another-variable/m-p/391101/hi...

 

The same approach (an array with one element per day) could be used here.

PG
devsas
Pyrite | Level 9
Thanks Sir, but its quite different problem as here we need the names of drugs concatenated instead. Also, i dont understand that code either.
devsas
Pyrite | Level 9

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-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
  • 3 replies
  • 1236 views
  • 0 likes
  • 2 in conversation