Hi all,
I really need your advice asap to create intervals of 3 months between 2 dates for all ids : begin_date and final_date. For the example provided (see file attached), the 2 dates are within 3 months of each other, but I could have the final_date in the analysis anywhere from 1 to 12 or more months apart.
The example provided is for id=604. It has begin_date, final_date, event_number, event_date. All the dates had a format of yymmdd10. I first converted the 'begin_date' into a sas date callled 'begin_date2' to use the intnx function. Below is my code:
I created 2 start and end dates ..int1start, int1end, int2start, int2end and 2 intervals p_int1 and p_int2 . I gave the interval a value of '1' or '0' : '1' if the final_date was between the start and end dates for the interval and '0' if the final_date was absent between the start and end dates for the interval.
I would like to know if there is faster way to do this. How can I ask for the final_date to determine the 'last end date' for the 'last interval? Basically, how can stop creatung the interval dates? The final_date has to be within the last interval period. Also, can I create these interval start and end dates using macro and also the intervals p_int1 etc.? Please let me know and do look at the attachment for the end result of the code below. I would like to know about a shorter way to accomplish the same.Thanks.
SAS CODE:
begin_date2=begin_date; /* converted into a sas date*/
int1start=begin_date2 ;
int1end=intnx('month',begin_date2,3,'same')-1 ;
int2start=intnx('month',int1end,0,'same')+1 ;
int2end=intnx('month',int2start,3,'same')-1 ;
format int1start int1end int2start int2end yymmdd10.;
if int1start le final_date_new lt int1end then p_Int1=1 ;
else if int2start le final_date_new lt int2end then p_Int2=1 ;
format int1start int1end int2start int2end yymmdd10.;
I also wanted to add that these intervals have to be determined for many others ids in the dataset.
... View more