The TODAY function yields a date, which is number of days from 1 Jan 1960. So when you format it with a DATETIME format, which expects the number of seconds you get a date part of the datetime value close to 1 Jan1960.
You can get a datetime using the DHMS function with the today() in the date position and in the remaining parameters
In a data step this would look like:
dt = dhms(today(),0,0,0);
or pick different time elements if needed.
Instead of spending time building date or datetime literal values, which appears you are doing just use the numeric value.
A comparison of
if thisvar > 21349 then ..
is just as valid as
if thisvar > '14JUN2018'd then ...
and will require less manipulation such as Putn.
Literal values may be important when humans read code but generated code for the computer often makes more sense to leave the numeric. Also the way you are currently using the macro variable as
where end_date > &system_date
would be incorrect if the system_date contains 14JUN2018:00:00:00.
if your end_date is a datetime value then the comparison would be
where end_date > "&system_date"dt
and if end_date is character getting the correct comparison would be more a matter of luck as any date of the 15th a month would be greater than the character value. Test it yourself to see if "15JAN2010:00:00:00" is greater than "14DEC2018:00:00:00".
If the purpose is to compare a date to a date that you can calculate to create a macro variable then use the similar calculation directly in the code:
if end_date > dhms(today(),0,0,0)
or if you need an offset such as the beginning of the month nest the date portion with a call to the intnx function.
... View more