Hi @NewUsrStat, it isn't immediately clear what your desired outcome should be. From your initial description, of wanting to compare values in different datasets, it seems like you're trying to do a merge by ID, admission and discharge date. So far so good, you can achieve that with a DATA step merge (of course, making sure data is pre-sorted):
data want;
merge db db1;
by id admission discharge;
format admission discharge date9.;
run;
However, you also mention that the output dataset should contain a new variable (which you don't provide an example for). In your last dataset DB2, you have examples that don't quite align with your previous observations in DB and DB1. For example, how did we get this observation in DB2?
166 16FEB2019 26FEB2019 1 0
This observation doesn't meet the requirement specified: only the case in which Variable_ =1 and Variable =0.
... View more