BookmarkSubscribeRSS Feed
Tomcaty
Obsidian | Level 7

I have the following data set that I would like to use to calculate overlapping days between two drugs. If the overlap period is  >=28 days then flag the ID. 

 

Source: 

IDDrug1d1start_dtd1End_dtDrug2d2start_dtd2End_dt
1A12-Jul-1710-Oct-17B..
2B1-Jan-0030-Jan-02A10-Apr-0130-Nov-04
3C22-Aug-1820-Nov-18C..
4A12-Sep-1820-Dec-18A7-Dec-1816-Apr-19
5C4-Jun-1513-Mar-18C..
6D15-Jun-1813-Sep-18B29-Jul-1427-Aug-16
7A8-Jun-166-Sep-16D13-Aug-153-Aug-16
8G28-Mar-1626-Jun-16E..
9H13-Apr-1718-Jul-18H21-Jan-1810-Jun-18
10B20-Feb-174-Jun-17C..

 

Result:

IDDrug1d1start_dtd1End_dtDrug2d2start_dtd2End_dtOverlap daysFlag
1A12-Jul-1710-Oct-17B..00
2B1-Jan-0030-Jan-02A10-Apr-0130-Nov-042951
3C22-Aug-1820-Nov-18C..00
4A12-Sep-1820-Dec-18A7-Dec-1816-Apr-19130
5C4-Jun-1513-Mar-18C..00
6D15-Jun-1813-Sep-18B29-Jul-1427-Aug-1600
7A8-Jun-166-Sep-16D13-Aug-153-Aug-163901
8G28-Mar-1626-Jun-16E..00
9H13-Apr-1718-Jul-18H21-Jan-1810-Jun-181401
10B20-Feb-174-Jun-17C..00
1 REPLY 1
PaigeMiller
Diamond | Level 26

The overlap seems to be (if I am understanding you properly) when d2start_dt < d1End_dt (although it would be nice if you had stated that directly to eliminate my possible misunderstanding). If that's the case, then the relatively simple test of d1End_dt - d2start_dt >=28 results in a flag.

 

if d1End_dt - d2start_dt >= 28 then flag=1;
else flag=0;

This assumes that all of your dates are valid SAS dates, and not character strings. 

--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 298 views
  • 0 likes
  • 2 in conversation