BookmarkSubscribeRSS Feed
rahul11124
Fluorite | Level 6
This works but not the efficient one if we run this code on millions of row it will generate around 365 date for each row in do loop
Ksharp
Super User

OK. How big table do you have ?

If you really care about efficiency problem , try this one .

 

data have;
input Coverage_Start : date11. Termination_Date : date11. Member_Id;
format Coverage_Start  Termination_Date  date11. ;
cards;
24-Jul-19 1-Jun-21 42968701
24-Jul-19 1-Mar-21 42968701
29-Feb-20 1-Mar-20 42968701
16-Feb-19 1-Mar-19 42968701
1-Mar-17 1-Mar-18 42968701
1-Mar-16 1-Mar-17 42968701
1-Dec-15 31-Dec-16 42968701
;

data want;
 array date{99999} _temporary_ ;
do until(last.Member_Id);
 set have;
 by Member_Id;
 do i=Coverage_Start to Termination_Date;
   date{i}=1;min=min(min,i);max=max(max,i);
 end;
end;
 do i=min to max;
  if missing(date{i-1}) and not missing(date{i}) then start=i;
  if missing(date{i+1}) and not missing(date{i}) then do;end=i;output;end;
 end;
call missing(of date{*});
 format start end date11.;
 keep Member_Id start end;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 16 replies
  • 3644 views
  • 4 likes
  • 6 in conversation