I have a field that contains dates in the format YYYYMMDD (4-digit year, 2-digit month, 2-digit day). I want to read records where date is within the past 3 years from today’s date.
For example, today is 2023-08-31. So I want to read records where date is between 20200101 and 20230831, inclusive. This will return records from 2020, 2021, 2022, and up to today in 2023.
DEFINE DATA LOCAL
1 FILE1 VIEW OF SOME-FILE
1 #THREE-YEARS-AGO-YYYY (A4)
1 REDEFINE #THREE-YEARS-AGO-YYYY
2 N (N4)
1 #TODAY-YYYYMMDD (A8)
END-DEFINE
*
MOVE EDITED *DATX TO #THREE-YEARS-AGO-YYYY (EM=YYYY)
SUBTRACT 3 FROM #THREE-YEARS-AGO-YYYY.N
*
READ FILE1 FROM #THREE-YEARS-AGO-YYYY TO #TODAY-YYYYMMDD
...etc...