@mt88 wrote:
My datasets were too large to copy and paste so hopefully this smaller set works:
data A;
input ID Date :date9.;
format Date date9.;
datalines;
ID Date 204356 02/13/2019 204356 03/17/2019 204356 04/20/2019 204356 07/20/2019 204356 09/22/2019 204356 10/19/2019 205352 10/01/2017 205756 01/17/2018 205756 02/07/2018 205756 04/11/2018 205756 05/07/2018 205756 04/27/2018 205756 05/14/2018 205756 07/06/2018 205756 10/15/2018 205756 10/05/2018 205756 10/29/2018 205756 01/18/2019 205756 02/25/2019 205756 05/15/2019 205756 08/18/2019 205756 09/04/2019 205756 11/16/2019
data B;
input ID Date :date9.;
format Date date9.;
datalines;
ID Date 204356 02/08/2019 204356 03/22/2019 204356 04/25/2019 204356 07/25/2019 204356 09/27/2019 204356 10/24/2019 205352 10/06/2017 205756 01/22/2018 205756 02/12/2018 205756 04/16/2018 205756 05/02/2018 205756 05/02/2018 205756 05/09/2018 205756 07/11/2018 205756 10/10/2018 205756 10/10/2018 205756 10/24/2018 205756 01/23/2019 205756 02/20/2019 205756 05/20/2019 205756 08/13/2019 205756 09/09/2019 205756 11/11/2019
Copy/paste this to the program editor and submit it. Then fix it. Then post it again.
My code does exactly what you're after. Have you tested it?
My code on your posted sample data:
data a;
input ID Date :mmddyy10.;
format Date mmddyy10.;
datalines;
204356 02/13/2019
204356 03/17/2019
204356 04/20/2019
204356 07/20/2019
204356 09/22/2019
204356 10/19/2019
205352 10/01/2017
205756 01/17/2018
205756 02/07/2018
205756 04/11/2018
205756 05/07/2018
205756 04/27/2018
205756 05/14/2018
205756 07/06/2018
205756 10/15/2018
205756 10/05/2018
205756 10/29/2018
205756 01/18/2019
205756 02/25/2019
205756 05/15/2019
205756 08/18/2019
205756 09/04/2019
205756 11/16/2019
;
data b;
input ID Date :mmddyy10.;
format Date mmddyy10.;
datalines;
204356 02/08/2019
204356 03/22/2019
204356 04/25/2019
204356 07/25/2019
204356 09/27/2019
204356 10/24/2019
205352 10/06/2017
205756 01/22/2018
205756 02/12/2018
205756 04/16/2018
205756 05/02/2018
205756 05/02/2018
205756 05/09/2018
205756 07/11/2018
205756 10/10/2018
205756 10/10/2018
205756 10/24/2018
205756 01/23/2019
205756 02/20/2019
205756 05/20/2019
205756 08/13/2019
205756 09/09/2019
205756 11/11/2019
;
data want (keep = ID Date);
do until (last.ID);
set a;
by ID;
if first.ID then from = Date;
if last.ID then to = Date;
end;
do until (last.ID);
set b;
by ID;
if from <= Date <= to then output;
end;
run;
Result:
ID Date 204356 03/22/2019 204356 04/25/2019 204356 07/25/2019 204356 09/27/2019 205756 01/22/2018 205756 02/12/2018 205756 04/16/2018 205756 05/02/2018 205756 05/02/2018 205756 05/09/2018 205756 07/11/2018 205756 10/10/2018 205756 10/10/2018 205756 10/24/2018 205756 01/23/2019 205756 02/20/2019 205756 05/20/2019 205756 08/13/2019 205756 09/09/2019 205756 11/11/2019
Thank you for your help and patience.
Anytime
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.