BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Paul_NYS
Obsidian | Level 7

Hi

I am trying to determine if the dates in a variable are GE a specific date value and LE another date value (in bold). I have tried variations of the below and keep getting errors. Any syntax ideas?

data s1suffolkpre;

set s1;

if cnty_name="Suffolk";

format start mmddyy10.;

format stop mmddyy10.;

format filing1 mmddyy10.;

if filing1 ge '01/01/2008'd and filing1 le '12/31/2009'd;

end;

Paul

1 ACCEPTED SOLUTION

Accepted Solutions
DBailey
Lapis Lazuli | Level 10

You might try using '01Jan2008'd and '31Dec2009'd...if that doesn't work...you'll probably need to post some examples and the error message.

View solution in original post

5 REPLIES 5
DBailey
Lapis Lazuli | Level 10

You might try using '01Jan2008'd and '31Dec2009'd...if that doesn't work...you'll probably need to post some examples and the error message.

Anotherdream
Quartz | Level 8

Haha the general syntax for a date delimiter in sas HAS TO BE

DD Mon YYYY (no spaces).  Note I say Mon, meaning the character representation of the month.

so

05/01/2011 would HAVE to be 05Jan2001.

Sas does this because in different countries in the world, there is NOT a consistent way to format dates. Example in the US dates are in  MM/DD/YYYY, however in many parts of europe it is DD/MM/YYYY.

SO the field 05/01/2011 means May 1st 2011 in the US, however it means January 5th 2011 in other parts of the world.

Hope that helps!

Paul_NYS
Obsidian | Level 7

Thank you both--that worked. However, my format statements preceding the comparison statement both reference a date format of mm/dd/yyyy (format filing1 mmddyy10.;). This apparently is not an issue?

Paul

Anotherdream
Quartz | Level 8

Short answer No.

Longer answer; Do a bit more research into Dates in Sas, and the date literal (that's what you're doing when you call 'DDMonYYYY'd.

A FORMAT statement only affects the way the data is displayed, not how it is handled by the system. Remember all "dates" in sas are really numbers (they're the number of days between 1/1/1960 and your input date).  Try to format one of your dates as best12. to see what I mean.

As such, you're basically telling sas "show my dates in the format mmddyyyy10.", however they're REALLY a number.

WHen you do the date literal of "01Jan2008"d you're telling sas "I DON'T KNOW the numeric value for the date January 1st 2008, so please take this input string and convert it to that number for me". Then compare THAT NUMBER against my date field, and apply my other logic.

You can format a date ANY way you want, but it doesn't change how sas "handles" the date, only how it displays it.

Hope that helps

Paul_NYS
Obsidian | Level 7

Yes, that's fine. I didn't know dates were just a display. Thanks a lot (again)!

Paul

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 5 replies
  • 60996 views
  • 6 likes
  • 3 in conversation