BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PaigeMiller
Diamond | Level 26
Data should be presented as text, not as screen captures, as @PeterClemmensen has done.

Your example does not match your original problem description where there is a data set named A that has the first date and last date for an ID. We need data sets that match the problem description, or you need to change the problem description, so now they match.
--
Paige Miller
Kurt_Bremser
Super User

@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.

PeterClemmensen
Tourmaline | Level 20

My code does exactly what you're after. Have you tested it?

PeterClemmensen
Tourmaline | Level 20

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 
mt88
Calcite | Level 5

Thank you for your help and patience. 

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!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 20 replies
  • 2042 views
  • 1 like
  • 4 in conversation