|
"Paparodopoulos, Nikos" ha escrito:
> Dear List,
>
> I have the following situation:
>
> DATEX MODE
>
> 27-OCT-1998 360
> 03-JUL-1997 180
> 11-MAY-2000 90
> 30-AUG-2001 60
>
> where MODE stands for # of days for 12 , 6, 3, 2 months respectively.
>
> I want to create a new column DATENEW as a result of the following:
>
> DATENEW=DATEX-TIME.DAYS(MODE).
> FORMATS DATEX(DATE11).
> VARIABLE WIDTH DATEX(11).
>
> but this does not produce: 27-OCT-1997, 03-JAN-1997, 11-FEB-2000 &
> 30-JUN-2001 respectively, as I would have expected.
Hi Nikos
360 days is not 12 months, nor a year (365.25 days is closer, more or
less). You have to use months instead of days an substract them from the
month of the date. This is quite straightforward when the number of
months to be substracted is lower than the month within the date, but
more complicated in the other case.
Try this:
DATA LIST LIST /datex(DATE11) monthx(F8.0).
BEGIN DATA
27-OCT-1998 12
03-JUL-1997 6
11-MAY-2000 3
30-AUG-2001 2
END DATA.
COMPUTE da = xdate.mday (datex).
COMPUTE mo = xdate.month(datex).
COMPUTE yr = xdate.year (datex).
DO IF (mo GT monthx).
COMPUTE mo=mo-monthx.
ELSE IF (mo LE monthx).
COMPUTE yr=yr-1.
COMPUTE mo=mo+12-monthx.
END IF.
EXEC.
COMPUTE datenew = date.dmy(da,mo,yr).
EXEC.
FORMATS datenew (DATE11).
VARIABLE WIDTH datenew (11).
Regards
Marta Garcia-Granero
|