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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 16 replies
  • 1585 views
  • 4 likes
  • 6 in conversation