BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
GreggB
Pyrite | Level 9
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.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
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.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
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.

--
Paige Miller
Quentin
Super User

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).

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 3839 views
  • 1 like
  • 3 in conversation