AYM: Adding or Subtracting Months

How to:

Available Languages: reporting, Maintain

The AYM function adds months to or subtracts months from a date in year-month format. You can convert a date to this format using the CHGDAT or EDIT function.

Syntax: How to Add or Subtract Months to or From a Date

AYM(indate, months, output)

where:

indate

I4, I4YM, I6, or I6YYM

Is the legacy date in year-month format, the name of a field that contains the date, or an expression that returns the date. If the date is not valid, the function returns the value 0 (zero).

months

Integer

Is the number of months you are adding to or subtracting from the date. To subtract months, use a negative number.

output

I4YM or I6YYM

Is the resulting legacy date. Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.

Tip: If the input date is in integer year-month-day format (I6YMD or I8YYMD), divide the date by 100 to convert to year-month format and set the result to an integer. This drops the day portion of the date, which is now after the decimal point.

Example: Adding Months to a Date

The COMPUTE command converts the dates in HIRE_DATE from year-month-day to year-month format and stores the result in HIRE_MONTH. AYM then adds six months to HIRE_MONTH and stores the result in AFTER6MONTHS:

TABLE FILE EMPLOYEE
PRINT HIRE_DATE AND COMPUTE
HIRE_MONTH/I4YM = HIRE_DATE/100 ;
AFTER6MONTHS/I4YM = AYM(HIRE_MONTH, 6, AFTER6MONTHS);
BY LAST_NAME BY FIRST_NAME
WHERE DEPARTMENT EQ 'MIS';
END

The output is:

LAST_NAME        FIRST_NAME  HIRE_DATE  HIRE_MONTH  AFTER6MONTHS
---------        ----------  ---------  ----------  ------------
BLACKWOOD        ROSEMARIE    82/04/01       82/04         82/10
CROSS            BARBARA      81/11/02       81/11         82/05
GREENSPAN        MARY         82/04/01       82/04         82/10
JONES            DIANE        82/05/01       82/05         82/11
MCCOY            JOHN         81/07/01       81/07         82/01
SMITH            MARY         81/07/01       81/07         82/01