BookmarkSubscribeRSS Feed
NewUsrStat
Lapis Lazuli | Level 10

Hi guys, 

suppose to have the following two datasets: 

The first one contains a full list of dates per ID and an index that indicates if the patient has a comorbidity (1) or not (0). Then, there's another dataset that contains a subset of dates from the first dataset and a RefDate, 1 or 0. What I would like to do is the following: 

 

for each ID:

  • if the comorbidity in DB1 = 1(!) before or =  to the Start_Therapy where in DB2 RefDate = 1 then add an Index in DB1 equal to 1 otherwise the Index should be 0 regardless if in DB1 the comorbidity = 1.
  • if the comorbidity in DB1 = 0 it should remain 0.

Thank you in advance!

 

Desired output = DB3

 

 

 

data DB1;
  input ID Start_Therapy Comorbidity;
  format Start_Therapy date9.;
cards;
0001 01OCT2015  1
0001 06DEC2016  1
0001 08NOV2020  1
0002 11JAN2014  0
0002 16JUN2014  0
0002 14MAY2015  1
0002 30JUN2015  1
0002 25FEB2016  0
0003 11SEP2012  0
0003 24AUG2014  1
0003 10DEC2014  1
0004 03JAN2014  0
0004 09FEB2014  1
0004 03AUG2015  1
0004 18MAY2016  0
;


data DB2;
  input ID Start_Therapy  RefDate;
  format Start_Therapy date9.;
cards;
0001 06DEC2016  1
0001 08NOV2020  0
0002 16JUN2014  1
0002 30JUN2015  0
0003 24AUG2014  1
0003 10DEC2014  0
0004 03AUG2015  1
;

data DB3;
  input ID  Start_Therapy  Comorbidity Index;
  format Start_Therapy date9.;
cards;
0001 01OCT2015  1  1
0001 06DEC2016  1  1
0001 08NOV2020  1  0
0002 11JAN2014  0  1
0002 16JUN2014  0  1
0002 14MAY2015  1  0
0002 30JUN2015  1  0
0002 25FEB2016  0  0
0003 11SEP2012  0  0
0003 24AUG2014  1  1
0003 10DEC2014  1  0
0004 03JAN2014  0  0
0004 09FEB2014  1  1
0004 03AUG2015  1  1
0004 18MAY2016  0  0
;

 

 

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Your title talks about creating a level. The rest of your post never mentions creating a label. Please clarify.

--
Paige Miller
NewUsrStat
Lapis Lazuli | Level 10
I'm sorry. It is intended as a label (new) column/index column

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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