- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yes, that's fine. I didn't know dates were just a display. Thanks a lot (again)!
Paul