suppose to have the following:
data have; input ID :$20. Start :date9. End :date9.; format start end ddmmyy9.; cards; 0001 01JAN2015 30JUN2015 0001 01JUL2015 01FEB2016 0001 02FEB2016 11DEC2016 0001 12DEC2016 06FEB2017 0001 07FEB2017 31DEC2017 0002 01JAN2016 31DEC2017 0002 01JAN2018 01MAR2018 0002 01APR2018 31NOV2018 ...................... ;
and a list of dates:
data dates;
input dates :$20.;
format dates ddmmyy9.;
cards;
01JAN2015
31DEC2015
01JAN2016
31DEC2016
01JAN2017
31DEC2017
01JAN2018
31DEC2018
;
Is there a way to know if, for each ID, each date is in the range? For example: the ID 0001 contains all dates except 01JAN2018 and 31DEC2018. Moreover, for each year I need to count how many IDs start at 01/01 and end at 31/12 so they appear for the entire year. For example, ID 0002 will not be counted for 2018 because it ends before 31/12. Desired output:
ID 01JAN2015 31DEC2015 01JAN2016 31DEC2016 01JAN2017 31DEC2017 01JAN2018 31DEC2018 0001 yes yes yes yes yes yes no no 0002 no no yes yes yes yes yes no
Final table:
Year Count 2015 1 2016 2 2017 2 2018 0
To match the dates in the range I tried:
proc sql; create table want as; select dates as t1; join have as t2; t2.dates between t1.start and t1.end order by 1,2; quit;
Unfortunately I lose the ID correspondence.
Can anyone help me please?
Thank you in advance