DATA Step, Macro, Functions and more

How to assess switch from one value to another

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 128
Accepted Solution

How to assess switch from one value to another

[ Edited ]
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. 


Accepted Solutions
Solution
‎02-22-2016 05:44 AM
Super User
Posts: 10,023

Re: How to assess switch from one value to another

Posted in reply to lillymaginta

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;

View solution in original post


All Replies
Super User
Posts: 10,023

Re: How to assess switch from one value to another

Posted in reply to lillymaginta

Your data is not completed . There are lots of missing value . 

And what output do you want ?

Frequent Contributor
Posts: 128

Re: How to assess switch from one value to another

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. 

 

Solution
‎02-22-2016 05:44 AM
Super User
Posts: 10,023

Re: How to assess switch from one value to another

Posted in reply to lillymaginta

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;
Frequent Contributor
Posts: 128

Re: How to assess switch from one value to another

Thank you!
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 237 views
  • 1 like
  • 2 in conversation