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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
* Adding 3 months to a given date is more difficult than it first looks.
* Increasing the number of months by 3 (and subtracting 12 if results exceed 12) gives results such as
* for 31/3/2000  --> 31/6/2000 (but June has only 30 days).
* Adding 90 or 91 days also produce weird results such as
* for 2000/12/1 --> 2001/03/02 (see variable dtpls91 in data editor).
* rlevesque@videotron.ca.

DATA LIST /date1(DATE12).

BEGIN DATA.
30-DEC-1999
31-JAN-2000
29-MAR-1999
30-MAR-1999
31-MAR-1999
1-APR-1999
5-FEB-1999
28-NOV-1999
29-NOV-1999
30-NOV-1999
28-NOV-2000
29-NOV-2000
30-NOV-2000
15-DEC-1998
1-DEC-2000
1-DEC-1999
END DATA.

SORT CASES BY date1.
COMPUTE day1=XDATE.MDAY(date1).
COMPUTE month1=XDATE.MONTH(date1).
COMPUTE year1=XDATE.YEAR(date1).
EXECUTE.

DO IF (ANY(month1,1,3,8) & (day1=31)).
COMPUTE flag=1.
COMPUTE date2=DATE.DMY(30, month1 +3,year1).
ELSE IF ( (month1=11) & (day1>28) ).
* in next compute. the 86400 is 60*60*24 that is the number of seconds in one day. 
* By subtracting one day from March 1st, results self adjust for leap years.
COMPUTE date2=DATE.DMY(1,3,year1+1)-86400.
COMPUTE flag=2.
ELSE IF (month1<10).
COMPUTE date2=DATE.DMY(day1, month1 + 3 ,year1).
COMPUTE flag=3.
ELSE.
COMPUTE flag=4.
COMPUTE date2=DATE.DMY(day1, month1-9 ,year1+1).
END IF.

COMPUTE dtpls91=date1+91*86400.
FORMAT date2 dtpls91(DATE12).
VARIABLE WIDTH date1 date2(13).
EXECUTE.