id rx1 rx_date h_date
1 a 1/1/2005 1/20/2005
1 b 2/2/2005
1 c 3/3/2005
2 a 1/2/2003 1/12/2003
2 a 2/2/2003
2 a 4/4/2003
3 b 1/2/2005 1/18/2005
3 c 2/3/2005
3 b 3/4/2005
I have a data similar to this. Patients can have multiple drug therapy rx1 in the same rx_Date or in different rx_date, I wanted to assess the patterns of change. For example I wanted to know how many patients switched one drug to another after h_date. Patient 1 was on a then after h_Date switched to b, patient 2 was on a and cont on a after h_Date.
OK. There is only one h_Date for each patient.
data have;
input id rx1 $ (rx_date h_date) (: mmddyy10.);
format rx_date h_date mmddyy10.;
cards;
1 a 1/1/2005 1/20/2005
1 b 2/2/2005 .
1 c 3/3/2005 .
2 a 1/2/2003 1/12/2003
2 a 2/2/2003 .
2 a 4/4/2003 .
3 b 1/2/2005 1/18/2005
3 c 2/3/2005 .
3 b 3/4/2005 .
;
run;
data temp;
set have(keep=id rx1 rx_date )
have(keep=id rx1 h_date rename=(h_date=rx_date) where=(rx_date is not missing) in=inb);
by id rx_date ;
if inb=0 and lag(inb)=1 or first.id;
run;
proc sql;
select *
from temp
group by id
having count(distinct rx1) gt 1
order by id,rx_date ;
quit;
Your data is not completed . There are lots of missing value .
And what output do you want ?
There is only 1 h_date per patient. I want the proprtion of patient who change rx1 (in a time period of 30 days) after h_date
proprtion of those who remain on a after h_date (patient 2), those who change from a to b (patient a) and so on.
OK. There is only one h_Date for each patient.
data have;
input id rx1 $ (rx_date h_date) (: mmddyy10.);
format rx_date h_date mmddyy10.;
cards;
1 a 1/1/2005 1/20/2005
1 b 2/2/2005 .
1 c 3/3/2005 .
2 a 1/2/2003 1/12/2003
2 a 2/2/2003 .
2 a 4/4/2003 .
3 b 1/2/2005 1/18/2005
3 c 2/3/2005 .
3 b 3/4/2005 .
;
run;
data temp;
set have(keep=id rx1 rx_date )
have(keep=id rx1 h_date rename=(h_date=rx_date) where=(rx_date is not missing) in=inb);
by id rx_date ;
if inb=0 and lag(inb)=1 or first.id;
run;
proc sql;
select *
from temp
group by id
having count(distinct rx1) gt 1
order by id,rx_date ;
quit;
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.