BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
CathyVI
Pyrite | Level 9

Hello,

I want to determine whether an individual completed any form (event_date) within 60 days of their program (end_date).

I have a demo data below and am struggle with the code. Any help please. 

data A;
input ssn @4 start_date :date9. @14 end_date :date9. @24 event_date :date9. ;
infile datalines  firstobs=2 ;
informat start_date end_date event_date date9.;
format start_date end_date event_date date9.;
datalines;
id    start_date	    end_date	 event_date   
101 01DEC2021	28FEB2022	09NOV2020    
101 16OCT2019	18NOV2019	03FEB2020    
102 16OCT2019	18NOV2019	07MAY2020    
103 03FEB2022	02MAY2022	08JUL2022    
103 03FEB2022	12FEB2022	15JAN2023    
;;
run;

 For example, id 101 first end_date was 28FEB2022 but the event date was less than 60days there the first id will not be my desired output.

BUT id 101 second end_date was 18NOV2019but the event date is 60days more than the end_date therefore the second ID will be part of my desired output. I don't want to dedup any data by id so I can capture all multiple events within one person(id).

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
Mazi
Pyrite | Level 9
Data want;
set a;
diff = event_date - end_date;
If 0<=diff<=60 then flag = 1;
else if diff >60 then flag= 2;
run;

View solution in original post

7 REPLIES 7
yabwon
Onyx | Level 15

Do you mean like this:

data want;
  set A;
  where end_date+60 < event_date;
run;

?

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Mazi
Pyrite | Level 9

Do you wish to calculate the difference between the event date and end date?

CathyVI
Pyrite | Level 9

@Mazi @yabwon  I wish to find those dates that "if event_date is within 60days after the end_date. Those are the id of interest. Any event date that is more than 60 days after the end date is not of interest. 

Mazi
Pyrite | Level 9
The second ID is more than 60 days after the event date. In your first post you said you’d want this record in your output.

Or am I missing something ?
CathyVI
Pyrite | Level 9

@Mazi  if you have 60days to the enddate (enddate+60) and the results is within the event_date, thats what I want. If you add 60 to the enddate and the results is more, I want a separate output of it.

Mazi
Pyrite | Level 9
Data want;
set a;
diff = event_date - end_date;
If 0<=diff<=60 then flag = 1;
else if diff >60 then flag= 2;
run;
Mazi
Pyrite | Level 9
If flag = 1 then event_date is 60 days or less after end_date

If flag = 2 then event_date is more than 60 days after end_date

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1029 views
  • 3 likes
  • 3 in conversation