Service___End_Date Frequency Percent 09JUN21:00:00:00 5 0.48 15AUG21:00:00:00 4 0.39 19AUG21:00:00:00 1 0.10 30AUG21:00:00:00 1 0.10 01SEP21:00:00:00 1 0.10 15SEP21:00:00:00 1 0.10 12OCT21:00:00:00 1 0.10 29NOV21:00:00:00 1 0.10
I want a statement that will delete the record if the Service___End_Date occured before today, regardless of when today is.
if datepart(Service___End_Date)<today() then delete;
Please note that comparing dates is NOT (and is NEVER) a format issue. The above will work regardless of the format of variable Sevice___End_Date.
It is an issue that a date/time value cannot be directly compared to a date value. Date/time values are on a different scale than date values, just like Celsius is on a different scale than Fahrenheit, and you can't compare them without first doing the conversion to the other scale. That is why DATEPART is needed, to obtain a date value that can be compared to another date value TODAY(), and then they are both on the same scale. As stated, in this case, the format is irrelevant, date values can be compared to other date values.
if datepart(Service___End_Date)<today() then delete;
Please note that comparing dates is NOT (and is NEVER) a format issue. The above will work regardless of the format of variable Sevice___End_Date.
It is an issue that a date/time value cannot be directly compared to a date value. Date/time values are on a different scale than date values, just like Celsius is on a different scale than Fahrenheit, and you can't compare them without first doing the conversion to the other scale. That is why DATEPART is needed, to obtain a date value that can be compared to another date value TODAY(), and then they are both on the same scale. As stated, in this case, the format is irrelevant, date values can be compared to other date values.
Please show what code you have tried.
Is Service___End_Date stored in a SAS date-time variable (i.e. numeric value) or is it a character string?
If it's a character string, would recommend using the INPUT function to read it into a date-time variable, and then comparing the value to the current date-time (which is returned by the DATETIME function).
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.