BookmarkSubscribeRSS Feed
Vison
Calcite | Level 5

I am dealing with health care enrollment data right now, facing the following problem.

Raw data looks like

ID             stard_date    end_date

P1            A                   B

P1            B+1               C

P1            C+180           D

P2              E                 F

P2              F+1             G                 

P3               H                I

 

The expected output is like

ID             stard_date    end_date

P1            A                   C

P1            C+180           D

P2              E                 G

P3               H                I

 

The criteria of difining  consecutive coverage or not could be parameterized, for example, in above example, if there is only 1 day gap, we consider it as consecutive, if the gap is large enough( 180 days), we don't concatenate them( see P1).

 

In addition, in order to make the ID as unique key, I am thinking about to change the ID as "ID+start date"

ID                       stard_date    end_date

P1+A                     A                   C

P1 +C+180           C+180            D

P2 +E                     E                  G

P3 +H                     H                  I

 

Thanks in advance

2 REPLIES 2
Ksharp
Super User

Should be good if you post some real date value rather than character .

 

 

data have;
input ID $   stard_date : date9.   end_date : date9.;
format stard_date end_date  date9.;
cards;
P1            01jan2012                   01jun2012
P1            02jun2012              01jun2013
P1             01jun2014           01dec2014
P2            01jun2012               01dec2012
P2              02dec2012             01jun2013                
P2                01jun2014            01jun2015
;
run;
data temp;
 set have;
 n+1;
 temp=stard_date; output;
 temp=end_date; output;
 drop stard_date end_date;
 format temp date9.;
run;
data temp;
 set temp;
 by id n;
 if first.id or (first.n and temp gt lag(temp)+1) then group+1;
run;
data x;
 set temp;
 by group;
 if first.group or last.group;
run;
proc transpose data=x out=want(drop=_name_);
by id group;
var temp;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 646 views
  • 2 likes
  • 3 in conversation