1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
* need to compute number of days between cis)beg and cis_end that are within the Eligibility Period.
* the Eligibility Period goes from 1/1/2003 to 1/31/2003 so the maximum is 31 days.
* Posted to SPSS newsgroup by Raynald Levesque on 2004/06/06.

DATA LIST LIST /cis_beg (ADATE11) cis_end (ADATE11).
BEGIN DATA
01/05/2003 01/05/2003
01/01/2003 01/31/2003
12/15/2002 02/02/2003
12/28/2002 01/15/2003
12/12/2002 12/18/2002
01/05/2003 05/04/2003
01/05/2003 01/07/2003
END DATA.
FORMATS cis_beg cis_end (ADATE11).

* 2 computes are used to facilitate understanding of the formula.
* The 2 commands could be combined in a single statement.

COMPUTE dur=CTIME.DAYS(
	MIN(DATE.DMY(31,1,2003),cis_end) -
	MAX(DATE.DMY(1,1,2003),cis_beg)
	) .
COMPUTE dayselig=MAX(0, dur + 1).
LIST.

* This is the result:
    cis_beg     cis_end      dur dayselig

01/05/2003  01/05/2003       .00     1.00
01/01/2003  01/31/2003     30.00    31.00
12/15/2002  02/02/2003     30.00    31.00
12/28/2002  01/15/2003     14.00    15.00
12/12/2002  12/18/2002    -14.00      .00
01/05/2003  05/04/2003     26.00    27.00
01/05/2003  01/07/2003      2.00     3.00