DATA Step, Macro, Functions and more

How to examine a date between two variables that are dates

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

How to examine a date between two variables that are dates

Hi,

I am trying to analyze data involving if there was a hospitalization (Y/N) in the first 6 months from a transplant date.  TRR transplant date is the date of transplant, SAS180 is 180 days after date of transplant, and then TRF status date is the date of follow up.

 

I want to tell SAS to look at Y/N for hospitalization if the TRF status date is between the time interval "date of transplant" and "SAS180". And remove any record if TRF status date is beyond the SAS180 date.  Does anyone know what I can do to achieve this? 

 


Thanks!

 

 


Screen Shot 2016-11-15 at 12.01.32 AM.png

Accepted Solutions
Solution
‎11-22-2016 11:34 PM
Super User
Posts: 17,784

Re: How to examine a date between two variables that are dates

Use INTNX to set the date to the end of the month. You can do this within your comparison rather than create a new variable. 

View solution in original post


All Replies
Super User
Posts: 17,784

Re: How to examine a date between two variables that are dates

Can you assume you'll always have dates or do you need to account for missing data? 

 

Anyways, you can compound your conditions using an AND

 

Length check $3.;

if status>=transplant AND STATUS<=sas180 then check='ok';

else check='bad';

 

Then you can filter on your check variable. I create this variable so I can confirm my code before removing records - makes it easier to debug. 

Occasional Contributor
Posts: 5

Re: How to examine a date between two variables that are dates

Thanks I will give this a try!

 

Ideally, I would want to capture if TRR Status Date was even within the same month and year of SAS 180 (if exceeds the interval by a few days, no big deal). But I feel that is too complicated in SAS? I was going to manually read it over.

Occasional Contributor
Posts: 5

Re: How to examine a date between two variables that are dates

What you suggested worked! 

 

Do you know if there is a way I can expand this a bit more so it is not just the 6 month SAS 180 exact date but includes the entire month of SAS180 date? 

 

So if the follow up date was 5/10/16  and the SAS 180 date was 5/05/16, I still want that to be included...

Solution
‎11-22-2016 11:34 PM
Super User
Posts: 17,784

Re: How to examine a date between two variables that are dates

Use INTNX to set the date to the end of the month. You can do this within your comparison rather than create a new variable. 

Super User
Posts: 17,784

Re: How to examine a date between two variables that are dates

Set it to the end of the month instead of beginning

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 229 views
  • 0 likes
  • 2 in conversation