BookmarkSubscribeRSS Feed
catkat96
Obsidian | Level 7

I have two datasets:

 

data snippet1;
input ID callDate :ddmmyy. start_date :ddmmyy. end_date :ddmmyy. cured ;
format Date start_date end_date ddmmyy10.;
datalines4;
001 30/11/2020 28/11/2020 01/12/2020 Cured
001 01/12/2020 28/11/2020 01/12/2020 Cured
001 30/12/2020 28/12/2020 04/01/2021 Not Cured
001 31/12/2020 28/12/2020 04/01/2021 Not Cured
001 01/02/2021 28/01/2021 01/02/2021 Cured
;;;

data have1;
input ID event_date :ddmmyy. description ;
format event_date ddmmyy10.;
datalines4;
001 28Oct2020
001 29Nov2020
001 29Nov2020 New Plan
001 30Nov2020
001 01Dec2020
001 01Dec2020 New Plan
001 01Dec2020 Stop Category
001 01Dec2020 Review Date
001 02Dec2020
001 02Dec2020 OLd Contact Strategy Level
001 02Dec2020
001 04Dec2020 Stop Category
001 04Dec2020 Review Date
001 29Dec2020
001 29Dec2020 New Plan
001 30Dec2020
001 31Dec2020
001 01Jan2021
001 01Jan2021
001 02Jan2021
001 04Jan2021
001 05Jan2021 OLd Contact Strategy Level
001 05Jan2021
001 29Jan2021
001 29Jan2021 New Plan
001 30Jan2021
001 31Jan2021
001 01Feb2021
001 01Feb2021
001 02Feb2021
001 02Feb2021 OLd Contact Strategy Level
001 02Feb2021
;;;

 

I'm trying to get, basically `Snippet1` with an two column called `Description1` and `Description2` which will grab the first and last description, respectively, of each period between `Calldate + Calldate+2`. So for `Calldate = 02Dec2020, Description1 = OLd Contact Strategy Level and Description2= Review Date`

I have more ID's of course, but I think just with one it is enough to see my problem anyways.

This is the code I have so far:

proc sql;
create table want as
select a.*
, min(c.description) as description1
, max(c.description) as description2
from snippet1 a
inner join
have1 c
on a.id= c.id
and a.calldate<= c.event_date
and c.event_date <= a.calldate+ 2
Group by 1;
Quit;

But this is the outcome:

data snippet1;
input ID callDate :ddmmyy. start_date :ddmmyy. end_date :ddmmyy. cured description1 description2;
format Date start_date end_date ddmmyy10.;
datalines4;
001 01/12/2020 28/11/2020 01/12/2020 Cured New Plan Stop Category
001 30/11/2020 28/11/2020 01/12/2020 Cured New Plan Stop Category
001 30/11/2020 28/11/2020 01/12/2020 Cured New Plan Stop Category
001 30/11/2020 28/11/2020 01/12/2020 Cured New Plan Stop Category
001 01/12/2020 28/11/2020 01/12/2020 Cured New Plan Stop Category
001 01/12/2020 28/11/2020 01/12/2020 Cured New Plan Stop Category
001 30/11/2020 28/11/2020 01/12/2020 Cured New Plan Stop Category
001 30/11/2020 28/11/2020 01/12/2020 Cured New Plan Stop Category
001 30/12/2020 28/12/2020 04/01/2021 Not Cured New Plan Stop Category
001 01/12/2020 28/11/2020 01/12/2020 Cured New Plan Stop Category
001 30/11/2020 28/11/2020 01/12/2020 Cured New Plan Stop Category
001 30/11/2020 28/11/2020 01/12/2020 Cured New Plan Stop Category
001 01/12/2020 28/11/2020 01/12/2020 Cured New Plan Stop Category
001 30/12/2020 28/12/2020 04/01/2021 Not Cured New Plan Stop Category
001 01/12/2020 28/11/2020 01/12/2020 Cured New Plan Stop Category
001 01/12/2020 28/11/2020 01/12/2020 Cured New Plan Stop Category
001 01/12/2020 28/11/2020 01/12/2020 Cured New Plan Stop Category
001 30/11/2020 28/11/2020 01/12/2020 Cured New Plan Stop Category
001 31/12/2020 28/12/2020 04/01/2021 Not Cured New Plan Stop Category
001 31/12/2020 28/12/2020 04/01/2021 Not Cured New Plan Stop Category
001 01/02/2021 28/01/2021 01/02/2021 Cured New Plan Stop Category
001 01/02/2021 28/01/2021 01/02/2021 Cured New Plan Stop Category
001 01/02/2021 28/01/2021 01/02/2021 Cured New Plan Stop Category
001 01/12/2020 28/11/2020 01/12/2020 Cured New Plan Stop Category
001 31/12/2020 28/12/2020 04/01/2021 Not Cured New Plan Stop Category
001 31/12/2020 28/12/2020 04/01/2021 Not Cured New Plan Stop Category
001 30/12/2020 28/12/2020 04/01/2021 Not Cured New Plan Stop Category
001 30/12/2020 28/12/2020 04/01/2021 Not Cured New Plan Stop Category
001 01/02/2021 28/01/2021 01/02/2021 Cured New Plan Stop Category
001 01/02/2021 28/01/2021 01/02/2021 Cured New Plan Stop Category
001 30/12/2020 28/12/2020 04/01/2021 Not Cured New Plan Stop Category
;;

As you can see, the dates repeat themselves a couple of times, and I'm not even sure all call dates are even properly in there.

Does anyone have any idea?

1 REPLY 1
ballardw
Super User

Please show what you expect the output to look like.

 

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
  • 1 reply
  • 346 views
  • 0 likes
  • 2 in conversation