BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lillymaginta
Lapis Lazuli | Level 10
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. 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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

4 REPLIES 4
Ksharp
Super User

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

And what output do you want ?

lillymaginta
Lapis Lazuli | Level 10

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. 

 

Ksharp
Super User

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;
lillymaginta
Lapis Lazuli | Level 10
Thank you!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 1178 views
  • 1 like
  • 2 in conversation