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 rx start_date   days_supply
1 a    1/1/2005     90 
2  b   2/2/2004      60 


Hi all, I have the above dataset, I want to divide the periods that the patient can take drug were days supply represent the days the patients taked the drug. For simplicity, if the patient have 90 days means patient takes the drug for 3 months. 60 for two months and so on. Here is the output I am looking for 

id rx start_date   days_supply
1  a   1/1/2005     30
1  a   2/1/2005     30 
1  a   3/1/2005    30
2  b   2/2/2004   30
2  b   3/2/2004   30 
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
       infile datalines;
       input id rx $ start_date mmddyy10. days_supply;
       format start_date mmddyy10.;
 datalines;
1 a 01/01/2005 90
2 b 02/02/2004 60
; run;
 
data want;
  set have;
       months = int(days_supply/30); 
	   supply=30;
       do i=1 to months;
          date = intnx('month',start_date,i-1,'s');
           output;
       end;
       KEEP ID RX supply date;
       format date mmddyy10.;
run;

View solution in original post

3 REPLIES 3
Shmuel
Garnet | Level 18

data have;

       infile datalines;

       input id rx start_date mmddyy10. days_supply;

       format start_date mmddyy10.;

 datalines;

1 a 01/01/2005 90

2 b 02/02/2004 60

; run;

 

data want;

  set have;

       months = days_supply / 30;   /* or ceil(days_supply/30)  */

       start_date_in = start_date;

       do i=1 to months;

           start_date = intnx('MONth', start_date_in, i-1) + day(start_date_in) -1;

           days_supply = 30;

           output;

       end;

run;

 

Ksharp
Super User
data have;
       infile datalines;
       input id rx $ start_date mmddyy10. days_supply;
       format start_date mmddyy10.;
 datalines;
1 a 01/01/2005 90
2 b 02/02/2004 60
; run;
 
data want;
  set have;
       months = int(days_supply/30); 
	   supply=30;
       do i=1 to months;
          date = intnx('month',start_date,i-1,'s');
           output;
       end;
       KEEP ID RX supply date;
       format date mmddyy10.;
run;
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
  • 3 replies
  • 791 views
  • 2 likes
  • 3 in conversation