BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
zhuxiaoyan1
Quartz | Level 8
NBRIDDRGSTART_DTEND_DTAdmit_ID
00158409W00100107746-Dec-1129-Jul-121
00158409W00100107746-Dec-1129-Jul-121
00158409W001001077430-Jul-1231-Jul-121
00158409W001001077430-Jul-1231-Jul-121
00211424W021001076516-Jan-1221-Sep-122
00324582W001011977524-Oct-1113-Feb-123
00324582W001011977524-Oct-1113-Feb-123
00330871W01100227665-Jan-1230-Aug-124
00330871W01100227665-Jan-1230-Aug-124
00334334W011001477513-Feb-1224-Oct-125
00334334W011001477513-Feb-1224-Oct-125
00337381W041001977525-Aug-1118-Apr-126
00337381W041001977525-Aug-1118-Apr-126
00340418W011000476620-Mar-1220-Dec-127
00340418W011000476620-Mar-1220-Dec-127
00345727W041001477522-Jul-111-Mar-128
00345727W041001477522-Jul-111-Mar-128
00347643W031001576611-Jan-1227-Apr-129
00347643W031001576611-Jan-1227-Apr-129
00348641W021002077523-Feb-121-Nov-1210
00348641W021002077523-Feb-121-Nov-1210
00355444W001002276610-Jan-1226-Oct-1211
00355444W001002276626-Oct-1226-Nov-1211
00367091W021002277424-Jan-1220-Jul-1212

 The above is my data. The Admit_ID is the variable that I need to create. my logic is not working. here is my code:

data want1;

set IPDat;

lag_NBR=lag(MBR_NBR);

lag_Prov=lag(PROV_ID);

lag_DRG=lag(DRG);

lag_Start=lag(EPI_START_DT);

lag_END=lag(EPI_END_DT);

if (MBR_NBR ne lag_NBR or Prov_ID ne lag_prov or DRG ne lag_DRG or EPI_START_DT ne lag_Start or EPI_END_DT ne lag_END) and

(EPI_START_DT - lag_END) not in (0, 1)

then counter + 1;

format lag_start lag_End date9.;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You're on the correct path.

 

However, you should make use of the BY variables as well.

 

Calculating the difference between start date  and previous end date is the biggest issue otherwise.

Untested, but should be close to what you need.

 

Also, this is asked every week so if you search on here you'll find many examples of how to solve this question.

 

data want;
set have;
by nbr id;

retain admit_id;

prev_end =lag(end_dt);

if not first.id and (start_dt - prev_end) > 1 then admit+1;
 
else if first.id then admit_id+1;

/*else you do nothing to keep the same value*/

run;

 

View solution in original post

2 REPLIES 2
Reeza
Super User

You're on the correct path.

 

However, you should make use of the BY variables as well.

 

Calculating the difference between start date  and previous end date is the biggest issue otherwise.

Untested, but should be close to what you need.

 

Also, this is asked every week so if you search on here you'll find many examples of how to solve this question.

 

data want;
set have;
by nbr id;

retain admit_id;

prev_end =lag(end_dt);

if not first.id and (start_dt - prev_end) > 1 then admit+1;
 
else if first.id then admit_id+1;

/*else you do nothing to keep the same value*/

run;

 

zhuxiaoyan1
Quartz | Level 8
Thank you very much, Reeza! It works perfectly.

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
  • 927 views
  • 0 likes
  • 2 in conversation