Flagging a date that occurs within two date variables

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Flagging a date that occurs within two date variables

Mags
Hello List

I am struggling with identifying a date within a range of date variables. I
want to know if a specific date - DecisionDate occurs within the date range
defined by client start and end dates. For example, does the decision date,
6/1/2008, for client X fall between his start date of 5/3/2007 and his end
date of 1/2/2009. For this client it would be 1 or yes. If the date does not
fall within that range, the returned valued would be 0 or No. To make this
more confusing, some of the start dates are missing. So, if the start date is
missing I want the returned value to be missing. Thus, the value of the new
variable (DateFlag) could be 1,0 or missing.

I'm trying to write syntax for this expression: if dDate is between Sdate and
EDate, then DateFlag = 1, otherwise 0, Unless Sdate is missing, then
DateFlag=missing.

Thanks for your help.

Mags

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Flagging a date that occurs within two date variables

Jim Marks

here is one solution:

NEW FILE.
DATA LIST LIST / id (f8.0) st_date d_date end_date (3adate10).
BEGIN DATA
1 , 05/03/2007 , 09/22/2007 , 01/06/2008
2 , 02/03/2009 , 09/22/2011 , 01/06/2010
3 , , 04/29/2009 , 08/11/2011
END DATA.
LIST.

COMPUTE good_decision = d_date GE st_date and d_date LT end_date.
FREQUENCIES good_decision.

Jim Marks
Sr Market Research Manager
National Market Research
Kaiser Foundation Health Plan of the Mid-Atlantic States, Inc.
2101 E. Jefferson St.
Rockville, MD 20852
Phone: (301) 816-6822
Cell Phone: (301) 456-6164

NOTICE TO RECIPIENT:  If you are not the intended recipient of this e-mail, you are prohibited from sharing, copying, or otherwise using or disclosing its contents.  If you have received this e-mail in error, please notify the sender immediately by reply e-mail and permanently delete this e-mail and any attachments without reading, forwarding or saving them.  Thank you.




From:        Mags <[hidden email]>
To:        [hidden email]
Date:        06/25/2013 10:28 AM
Subject:        Flagging a date that occurs within two date variables
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Hello List

I am struggling with identifying a date within a range of date variables. I
want to know if a specific date - DecisionDate occurs within the date range
defined by client start and end dates. For example, does the decision date,
6/1/2008, for client X fall between his start date of 5/3/2007 and his end
date of 1/2/2009. For this client it would be 1 or yes. If the date does not
fall within that range, the returned valued would be 0 or No. To make this
more confusing, some of the start dates are missing. So, if the start date is
missing I want the returned value to be missing. Thus, the value of the new
variable (DateFlag) could be 1,0 or missing.

I'm trying to write syntax for this expression: if dDate is between Sdate and
EDate, then DateFlag = 1, otherwise 0, Unless Sdate is missing, then
DateFlag=missing.

Thanks for your help.

Mags

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

Reply | Threaded
Open this post in threaded view
|

Re: Flagging a date that occurs within two date variables

David Marso
Administrator
In reply to this post by Mags
I like the RANGE function for such:
COMPUTE DateFlag= RANGE ( DecisionDate , StartDate , EndDate ).

Mags wrote
Hello List

I am struggling with identifying a date within a range of date variables. I
want to know if a specific date - DecisionDate occurs within the date range
defined by client start and end dates. For example, does the decision date,
6/1/2008, for client X fall between his start date of 5/3/2007 and his end
date of 1/2/2009. For this client it would be 1 or yes. If the date does not
fall within that range, the returned valued would be 0 or No. To make this
more confusing, some of the start dates are missing. So, if the start date is
missing I want the returned value to be missing. Thus, the value of the new
variable (DateFlag) could be 1,0 or missing.

I'm trying to write syntax for this expression: if dDate is between Sdate and
EDate, then DateFlag = 1, otherwise 0, Unless Sdate is missing, then
DateFlag=missing.

Thanks for your help.

Mags

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Flagging a date that occurs within two date variables

Mags
In reply to this post by Mags
Thanks to Jim and David for their syntax.

Jim's syntax worked perfectly. It is exactly what I needed. I've never used
range, so I appreciate learning new syntax.


Mags

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Fw: Flagging a date that occurs within two date variables

Mags
Pardon me if any listers receive this email more than once. I don't know why the emails are not going through. I want to thank both Jim and David for their syntax.

Jim's syntax worked perfectly. It is exactly what I needed. I've never used range, so I appreciate learning the new syntax.

Thanks again. 

Mags