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

 

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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